C# How to kill parent thread

Posted by Royson on Stack Overflow See other posts from Stack Overflow or by Royson
Published on 2010-04-29T13:00:23Z Indexed on 2010/04/29 13:47 UTC
Read the original article Hit count: 329

Filed under:
|
|
|
|

A parent has several child threads.

If user click on stop button the parent thread should be killed with all child threads.

//calls a main thread           
 mainThread = new Thread(new ThreadStart(startWorking));
 mainThread.Start(); 
////////////////////////////////////////////////
   startWorking()
{
    ManualResetEventInstance                    =   new ManualResetEvent(false);
    ThreadPool.SetMaxThreads(m_ThreadPoolLimit, m_ThreadPoolLimit);

    for(int i = 0; i < list.count ; i++)
   {        

        ThreadData obj_ThreadData   =   new ThreadData();
        obj_ThreadData.name      =   list[i];

        m_ThreadCount++;             

        //execute 
        WaitCallback obj_waitCallBack = new WaitCallback(startParsing);

        ThreadPool.QueueUserWorkItem(obj_waitCallBack, obj_ThreadData);
    }
  ManualResetEventInstance.WaitOne();
}

I want to kill mainThread.

© Stack Overflow or respective owner

Related posts about c#

Related posts about multithreading