Thread resume

  • Thread starter Thread starter fhunter
  • Start date Start date
F

fhunter

Hi,

Is there a way to resume, wakeup a Thread once you set it
to sleep? Compact Framework 2003.


Thank you
 
Have the thread wait on an event/time-out using WaitForSingleObject(). When
the time-out is set for four minutes, that will handle the periodic run.
When some other thread wants to release the waiting thread early, they can
SetEvent() (or whatever the actual P/Invoke call is, ModifyEvent() to pulse
the event, releasing the waiting thread once).

Paul T.
 
Couple of additional thoughts:

1) Use a smaller sleep interval and then use conditional logic to determine
whether you want to update the data or go back to sleep. (i.e. - instead
of sleeping for 4 mins and then updating, sleep for 1 and then either
update or go back to sleep).
2) You could also do something with events or lean on the ThreadPool class.
Setup a Timer with a callback that executes at your regular interval.
Then manually do something like QueuUserWorkItem to the same callback as
needed in between your regular interval. Just be sure you stay
thread-safe.

Best Regards,
Reed Robison
DST Premier Services

--------------------
Content-Class: urn:content-classes:message
From: "fhunter" <[email protected]>
Sender: "fhunter" <[email protected]>
References: <[email protected]>
Subject: Re: Thread resume
Date: Wed, 3 Sep 2003 13:26:22 -0700
Lines: 32
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcNyWaQ3wmz1+AtGSwO5fvSnHEaYyw==
Newsgroups: microsoft.public.dotnet.framework.compactframework
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.compactframework:32682
NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

So is there any other way to do this? I want to run a
continues loop every so often (every 4 mins for example).
But once in a while I want to update the data and have
the loop execute immediatelly.
Right now I am just creating a new thread which is very
inefficient.

This posting is provided "AS IS" with no warranties, and confers no rights.

Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm"
 
Back
Top