Click here to Skip to main content
15,918,668 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
in c# when no one is working in that form in C# window forms?
Very urgent, please Answer
Posted
Updated 17-Feb-15 21:19pm
v3
Comments
Sergey Alexandrovich Kryukov 18-Feb-15 3:08am    
Why? What have you tried so far?
One more advice: don't do anything urgently; this is a sure way to make bad things, such as the one you want to do now.
—SA

Here: "User Idle Detection"[^] a sample imlpementation using the Windows API function GetLastInputInfo. I don't know if the Framework provides an equivalent functionality.
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 18-Feb-15 3:11am    
The idea is not bad, even though the inquirer probably did not mean that. But overall, even this would the evil. Only the user knows exactly when to close something. But I voted 5 because there could be some rare reasons, such as security. But even then it will create more of illusion of safety than real safety. Please see also my answer.
—SA
You can find the idle time through GetLastInputInfo function
and then you can write you own logic to close the form or what you want.

Here is good article with the complete solution
Getting the user idle time with C#[^]

Hope, it helps :)
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 18-Feb-15 3:12am    
5ed, but please see my comment to Solution 1 (and that solution) and Solution 3 (especially last line :-)
—SA
The only ideal time for closing a form is the time when a user explicitly closes it by a mouse click or a keyboard.

If you think you know exact time better and has nothing else to do, you can use:
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.close%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/system.windows.forms.timer%28v=vs.110%29.aspx[^] (this is one of the very rare cases when one can use this timer type, which is good almost for nothing).

But better don't do evil.

—SA
 
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