Click here to Skip to main content
15,919,879 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a code like this:
C#
while (true)
            {
                _isoMsgProcessEvent.WaitOne();
                while (_isoRxFrameQueue.Count > 0)
                {
                    Iso15765Frame rxFrame = null;
                    lock (_isoRxFrameQueue)
                    {
                        rxFrame = _isoRxFrameQueue.Dequeue();
                        //Do all processing for the recieved iso frame.
                        
                    }
                    ProcessTxMsg(rxFrame);
                }
                _isoMsgProcessEvent.Reset();
            }


This is happening in a worker thread. In this i have to handle ThreadAbort exception.
Can someone explain best way to do the cleanup for thread. What all things might happen if such exception is thrown.


This is how i have started this thread:
C#
_isoProcessingThread = new System.Threading.Thread(new System.Threading.ThreadStart(ProcessIsoMessagesProc));
Posted

 
Share this answer
 
use try-catch to catch the ThreadAbortException and do your clean up in the catch block.

There is nothing wrong with the way you use threads, but I though make you aware of the Task Parallel Library introduced in .NET 4.0.
Sacha Barber has written a series of articles about it here is the first one
Task Parallel Library: 1 of n[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900