Continously Running Thread

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Dear:

I used to code a continously running thread in C++ like following:
Handle hStopEvent = CreateEvent(NULL,true,false,NULL);
UINT uOptional = 0;
_beginthreadex(NULL,0,wtInvestigate,(LPVOID)NULL,0,&uOptional);

unsigned _stdcall
wtInvestigate(LPVOID lpParams)
{
while(true)
{
DWORD dwThreadStatus = WaitForSingleObject(hStopEvent
,DELAY_TIME);
switch(dwThreadStatus)
{
case WAIT_OBJECT_0:
//TODO
break;
case WAIT_TIMEOUT:
//TODO
break

}
}
}

How can I achieve the same procedure in C#
 
Raed Sawalha said:
I used to code a continously running thread in C++ like following:

How can I achieve the same procedure in C#

Just write a never-ending method, and create a thread to run that
method in the normal way. I very rarely write methods like that though
- the thread should usually watch for a certain condition at which
point it will shut down gracefully.

See http://www.pobox.com/~skeet/csharp/threads/ for more threading
information.
 

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

Back
Top