.Nico wrote:So with the thread.sleep() it will just wait for a while? It is suppose to do something every 30 minutes.
Yes, Thread.Sleep(x) will pause the current thread for x milliseconds, so Thread.Sleep(30 * 60 * 1000) will wait for 30 minutes. (Remember to "use System.Threading;" to get access to the Thread functions.)
Often, you might like a little more control than that, so you could use a signal with a 30-minute timeout. That way, you can signal your POP3 thread if you want it to do something else, like check immediately or exit.
For example:
Code: Select all
// Class declarations
AutoResetEvent pollEvent = new AutoResetEvent(false);
TimeSpan pollTime = new TimeSpan(0, 30, 0); // 30 minute interval
Thread pollThread;
// Initialisation code
pollThread = new Thread(new ThreadStart(this.runPollThread));
pollThread.IsBackground = true;
pollThread.Start();
// Thread function
void runPollThread()
{
while (true)
{
CheckForMail(); // Go check mail
if (pollEvent.WaitOne(polltime))
{
// Received an external signal, so do whatever we need to do (e.g. check a state variable to exit, restart poll, reread poll settings, etc)
}
else
{
// Timed out after 30 minutes - may not need to do anything explicit for this.
}
}
}
Then you can say pollEvent.Set(); from your main code if you need to wake up the poll loop before having the full 30 minutes elapse.
Eddy