Project Timeout

  • Thread starter Thread starter Bob Allen
  • Start date Start date
B

Bob Allen

I am working on an application that needs to timeout because of sensitive
information being displayed on the screen. Is there a way to flag the
application that nothing has happened for x number of seconds like a screen
saver would do? I have looked at using the mouse move events and the key
stroke events but i have so many controls in the app that this would be very
time consuming. So before undertaking this i was going to see if anyone has
a better idea?

Thanks;
Bob;
 
You could look at the Application.Idle event and do something with that.

Perhaps reset a timer to a certain amount every time the app enters the idle
state. If it stays there too long, the timer will expire and close the
window. You might need to use the threading timer instead of the message
based one.

--
Bob Powell [MVP]
C#, System.Drawing

September's edition of Well Formed is now available.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Blog http://bobpowelldotnet.blogspot.com
 
Hi,

Just some untested idea, get all keyboard and mouse action trough an
implemented IMessageFilter.


Class MyMessageFilter
------------------------
public class MyMessageFilter : IMessageFilter
{
public int TimerClicks_;

MyMessageFilter (MainForm frm)
{
TimerClicks_ = 0;
}

public bool PreFilterMessage(ref Message m)
{
if ( (m.Msg >= 0x200 && m.Msg <= 0x20D)) ||
(m.Msg >= 0x100 && m.Msg <= 0x108) )
{
// Console.WriteLine("Keyboard or Mouse msg: " + m.Msg);
TimerClicks_ = 0;
}

return false; // don't block messages
}
}

Class MainForm
----------------
public class MainForm : Form
{
// put timer on form, interval to e.g. 20000 (20sec)
private MyMessageFilter MessageFilter_;
private HideableForm frmHideable_; // this is the form which
auto-hides

MainForm()
{
frmHideable_ = new HideableForm();
MessageFilter_ = new MyMessageFilter();
Application.AddMessageFilter( MessageFilter_ );
// other stuff
}

timer-eventhandler()
{
++MessageFilter.TimerClicks_;
if (MessageFilter.TimerClicks == 30) // 30*20sec = 10min
{
Timer.Stop();
frmHideable.Hide();
}
}

void ShowHideableWnd()
{
Timer.Start();
frmHideable.Show();
}

}

HTH
greetings
 
Back
Top