October 25, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Managed Extensions: Tracking User Idle Time Without Hooks

  • October 4, 2004
  • By Tom Archer
  • Send Email »
  • More Articles »

The Client

Now let's discuss the client, or user, of the IdleTimer class. As should almost always be the case, the client is pretty simple as most of the code is in the class. The following function is an example of instantiating the IdleTimer object and specifying a callback function (Form1::UserIdleTooLong) that adheres to the IdleTimer::IdleTimerCallback delegate syntax. (The value 5000 being passed to the IdleTimer constructor indicates that the max idle time should not exceed 5000 milliseconds, or 5 seconds.)
void button1_Click(System::Object *  sender, System::EventArgs *  e)
{
  try
  {
    IdleTimer* idle = 
      new IdleTimer(5000, new IdleTimer::IdleTimerCallback(this, 
                                                          &Form1::UserIdleTooLong));
  }
  catch(Exception* e)
  {
#pragma push_macro("MessageBox")
#undef MessageBox
    MessageBox::Show(e->Message, 
                     S"Error", 
                     MessageBoxButtons::OK, 
                     MessageBoxIcon::Error);
#pragma pop_macro("MessageBox")
  }
}

You can then code the Form1::UserIdleTooLong function to perform whatever application-specific logic you need:

void UserIdleTooLong()
{
#pragma push_macro("MessageBox")
#undef MessageBox
  MessageBox::Show(S"Hey! Wake up!", 
                   S"Idle Time Warning", 
                   MessageBoxButtons::OK, 
                   MessageBoxIcon::Warning);
#pragma pop_macro("MessageBox")
}

About the Author

The founder of the Archer Consulting Group (ACG), Tom Archer has been the project lead on three award-winning applications and is a best-selling author of 10 programming books as well as countless magazine and online articles.





Page 2 of 2



Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel