Timers and threading

G

Guest

Hi,

I am writing a program that handles authentication, and based on the user's
permission level, can do certain things in the program. However, I want to
have a global 10 minute time out in case a user is idle for that amount of
time.

To do this, I am using a timer from System.Timers. At the end of the 10
minute timeout, I want the timer to call methods within the program to limit
access to certain functionality. However, the problem is that the timer is
working on a different thread, and so calls to these methods will also be on
this thread, which is not the owner thread of the controls I am trying to
alter, and so I'm getting an exception.

How can I tell the owner thread to manipulate the controls?

Thanks!
 
B

Bob Powell [MVP]

Use the BeginInvoke for asynchronous operations or Invoke for synchronous.

Generally, if you suspect that code might be running on another thread than
the UI thread you can use the InvokeRequired property to see if you should
use the invoke methods.

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

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

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

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top