M
Maloney
Exit thread in C#CF. I'm createing a thread and setting a class object for
when to exit. Before creating the thread i check if the thread is running,
if so set the flag to exit the thread.
What is the proper way of waiting for the thread to exit. In C++ i would
set an event and WaitForMultipleObject, peek and pump messages until the
handle was set.
Class test
{
private bool ExitThread = false
private bool ThreadRunning = false
private Thread myThread
private StartThread()
{
if(ThreadRunning)
{
ExitThread = true;
}
myThread = new Thread(new ThreadStart(FuncThread));
}
private FuncThread()
{
ThreadRunning = true;
while(more files)
{
if(ExitThread)
break;
read files in directory
Invoke back to main thread and fill item to list box
}
ThreadRunning = false;
}
}
when to exit. Before creating the thread i check if the thread is running,
if so set the flag to exit the thread.
What is the proper way of waiting for the thread to exit. In C++ i would
set an event and WaitForMultipleObject, peek and pump messages until the
handle was set.
Class test
{
private bool ExitThread = false
private bool ThreadRunning = false
private Thread myThread
private StartThread()
{
if(ThreadRunning)
{
ExitThread = true;
}
myThread = new Thread(new ThreadStart(FuncThread));
}
private FuncThread()
{
ThreadRunning = true;
while(more files)
{
if(ExitThread)
break;
read files in directory
Invoke back to main thread and fill item to list box
}
ThreadRunning = false;
}
}