In addition to both other comments...
If I understood your scenario, I'd go for the Threading.Timer... No need to
wake the Thread up every two seconds (or have that timespan diff stuff)...
When the tmr calls you back check for your flag (gblMessageThread) before
GetMessages... only then restart the Timer (in other words on
creation/Change sets the timer's period to -1). At the place where you set
your flag to False also dispose of the timer.
If for any other reason you *must* use a Thread, combine it with a
ManualResetEvent instead of waking the thread every 2 seconds for no real
reason...
Cheers
Daniel
"MDB" <nospam> wrote in message news:
[email protected]...
Thanks, I will stick with the thread then since it does take some time to
GetMessages.
Thanks Again
every
however,
I
am
unsure if it is the better way.
I also experimented with the timer by using this code:
******TIMER******
private System.Windows.Forms.Timer timerHTTP;
// CHecks Messages Every 20 Seconds
timerHTTP.Interval = 20000;
timerHTTP.Enabled = true;
private void timerHTTP_Tick(object sender, EventArgs e)
{
PMMobile.Classes.Globals.gMessage.GetMessages(false);
}
******* THREAD*******
private void RunMessageThread()
{
int intMessageSleep = 20; //How long in secs before running again.
DateTime dtMessageSleep = DateTime.Now; //Set Inital DateTime
//Int TimeDifference
TimeSpan intTimeDifference;
//Check right away
myApp.Classes.Globals.gMessage.GetMessages(false);
while(myApp.Classes.Globals.gblMessageThread)
{
//Get time difference and check to see if >= intSleep Time
intTimeDifference = DateTime.Now - dtMessageSleep;
if(myApp.Classes.Globals.gblMessageThread && intTimeDifference.Seconds
=
intMessageSleep)
{
myApp.Classes.Globals.gMessage.GetMessages(false);
dtMessageSleep = DateTime.Now;
}
//Sleep for 2 seconds
Thread.Sleep(2000);
}
}
"Chris Tacke, eMVP" <ctacke[at]OpenNETCF_dot_org> wrote in message
All depends on what the check does and how you want to implement it.
There
are also 2 different timers - Thread.Timer and Forms.Timer which
are
very
different in behavior.
-Chris
"MDB" <nospam> wrote in message
Hello All,
I have function that checks for messages every 30 seconds and was
wondering
if it is better to use a thread or timer to do this?