Ver Mensaje Individual
  #2 (permalink)  
Antiguo 07/02/2013, 08:53
Avatar de seba123neo
seba123neo
 
Fecha de Ingreso: febrero-2007
Ubicación: Esperanza, Santa Fe
Mensajes: 1.046
Antigüedad: 17 años, 2 meses
Puntos: 19
Respuesta: Como hacer que mi aplicacion despues de cierto tiempo sin uso se cierre?

Hola, esto se puede hacer obteniendo lo que se llama "user idle time", que seria el tiempo inactivo, se hace con una api llamada GetLastInputInfo, aca te paso un ejemplo simple de como detectar si estuvo 5 segundos inactiva, adaptalo a tus necesidades y lo unico que tendrias que hacer es cerrar la aplicacion cuando se cumpla esa condicion.

Código vb:
Ver original
  1. Imports System.Runtime.InteropServices
  2.  
  3. Public Class Form1
  4.  
  5.     Private Structure LASTINPUTINFO
  6.         Public cbSize As UInteger
  7.         Public dwTime As UInteger
  8.     End Structure
  9.  
  10.     <DllImport("User32.dll")> _
  11.     Private Shared Function GetLastInputInfo(ByRef plii As LASTINPUTINFO) As Boolean
  12.     End Function
  13.  
  14.     Public Function GetInactiveTime() As Nullable(Of TimeSpan)
  15.         Dim info As LASTINPUTINFO = New LASTINPUTINFO
  16.         info.cbSize = CUInt(Marshal.SizeOf(info))
  17.         If (GetLastInputInfo(info)) Then
  18.             Return TimeSpan.FromMilliseconds(Environment.TickCount - info.dwTime)
  19.         Else
  20.             Return Nothing
  21.         End If
  22.     End Function
  23.  
  24.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  25.         Timer1.Start()
  26.     End Sub
  27.  
  28.     Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
  29.         Dim inactiveTime = GetInactiveTime()
  30.  
  31.         If (inactiveTime Is Nothing) Then
  32.             Me.Text = "Desconocido"
  33.             Me.BackColor = Color.Yellow
  34.         ElseIf (inactiveTime.Value.TotalSeconds > 5) Then
  35.             Me.Text = String.Format("Inactivo por {0}segundos", inactiveTime.Value.TotalSeconds.ToString("#"))
  36.             Me.BackColor = Color.Red
  37.         Else
  38.             Me.Text = "Aplicacion Activa"
  39.             Me.BackColor = Color.Green
  40.         End If
  41.     End Sub
  42. End Class

solo tenes que poner un control Timer() en el formulario.

saludos.
__________________
" Todos Somos Ignorantes; lo que pasa es que no todos ignoramos las mismas cosas " - Albert Einstein