Click here to Skip to main content
15,888,059 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I would like to close some application if it was not used for certain amount of time in vb.net
Posted
Updated 29-May-12 17:33pm
v2
Comments
OriginalGriff 28-May-12 7:44am    
Sorry?
That doesn't make a lot of sense - users don't "set the system in idle" - the idle process is executed when the system has nothing else to do.
Why would you want to close an app because the system is not busy at this precise moment?
Use the "Improve question" widget to edit your question and provide better information.
Sergey Alexandrovich Kryukov 28-May-12 11:49am    
It makes no sense. I would just guess that you would like to close some application if it was not used for certain amount of time. Sometimes people asked about such things. If so -- bad idea.
--SA

If it is your own application you wish to close, then it isn't too bad:
Set up a timer, with (say) a one second interval.
Set up a timeout variable, and set it's value to the number of seconds of inactivity you want.
In the Timer Tick event handler, reduce the timeout variable by one. If it is zero, then call Application.Exit to close your application.
When you get user activity (and you will have to decide what that is) reset the Timeout variable to it's original value.

If this is VB.NET for real (as in a web based app) it is harder, as inactivity is difficult to detect in a client server system!
 
Share this answer
 
Comments
MarqW 30-May-12 3:43am    
"If this is VB.NET for real (as in a web based app)"
What an odd statement. Why would a web-based app make "VB.NET for real"? If anything, VB.NET should be "real" for desktop applications, since that is where the roots of VB lie. By the by though
OriginalGriff 30-May-12 4:04am    
The convention is to use "VB6" for pre .NET version of VB, "VB" for .NET desktop based, and "VB.NET" would be web based.
Or at least, That's what I have seen and used. :laugh:
This tutorial will tell you how to get the system's idle times. You can then combine this with the Diagnostics.Process class to kill or start any application you want
http://www.geekpedia.com/tutorial210_Retrieving-the-Operating-System-Idle-Time-Uptime-and-Last-Input-Time.html[^]

Edit: It's a C# article, but should give you enough to look up the P/Invokes and convert.
 
Share this answer
 
v2
Hi,
Here is what you want-
Application Idle[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900