Thread Abort Exception
-
<System.Threading.ThreadAbortException: Thread was being aborted. at System.Threading.WaitHandle.WaitOneNative(SafeWaitHandle waitHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext) at System.Threading.WaitHandle.WaitOne(Int64 timeout, Boolean exitContext) at System.Threading.WaitHandle.WaitOne(TimeSpan timeout, Boolean exitContext) at System.Threading.WaitHandle.WaitOne(TimeSpan timeout) > Exception like this. The web application, here on clicks, singleton object creates separate thread then that thread read a data read from xml file. using XMLDocument. then after read that file data updated to database, then waiting for another request for that, with in the thread ManuelResetEvent wait is performed, if comes next request from while onlick button its Ret and release the thread block and doing that same process. as per requirement,In between if needs, can change xml value dynamically, but when i edit that xml and saving, the thread was aborting automatically then entire application crashed. code is
private void XMlreaderProcess()
{
long delayTimeSpanTicks = 0;try { while (Active) { try { triggerCtrl.Reset(); if (delayTimeSpanTicks == 0) { triggerCtrl.WaitOne(); } else { triggerCtrl.WaitOne(new TimeSpan(delayTimeSpanTicks)); } StartProcess(); } catch(Exception ex) { delayTimeSpanTicks = 0; } finally { } } } catch(Exception ex) { } finally { Active= false; }
-
<System.Threading.ThreadAbortException: Thread was being aborted. at System.Threading.WaitHandle.WaitOneNative(SafeWaitHandle waitHandle, UInt32 millisecondsTimeout, Boolean hasThreadAffinity, Boolean exitContext) at System.Threading.WaitHandle.WaitOne(Int64 timeout, Boolean exitContext) at System.Threading.WaitHandle.WaitOne(TimeSpan timeout, Boolean exitContext) at System.Threading.WaitHandle.WaitOne(TimeSpan timeout) > Exception like this. The web application, here on clicks, singleton object creates separate thread then that thread read a data read from xml file. using XMLDocument. then after read that file data updated to database, then waiting for another request for that, with in the thread ManuelResetEvent wait is performed, if comes next request from while onlick button its Ret and release the thread block and doing that same process. as per requirement,In between if needs, can change xml value dynamically, but when i edit that xml and saving, the thread was aborting automatically then entire application crashed. code is
private void XMlreaderProcess()
{
long delayTimeSpanTicks = 0;try { while (Active) { try { triggerCtrl.Reset(); if (delayTimeSpanTicks == 0) { triggerCtrl.WaitOne(); } else { triggerCtrl.WaitOne(new TimeSpan(delayTimeSpanTicks)); } StartProcess(); } catch(Exception ex) { delayTimeSpanTicks = 0; } finally { } } } catch(Exception ex) { } finally { Active= false; }
Not wishing to touch your design (which sounds pretty dodgy), just explain this exception: A ThreadAbortException is raised within a thread when Thread.Abort is called on it. Either your code, or some framework code, must be doing that. My guess would be that the web framework kills any threads that were started as the result of a request once the request is finished, but it is just a guess – hopefully someone can post who actually knows the answer. Your posted code is swallowing exceptions – and it also appears to be using exceptions as part of normal code flow control, which is probably worse.
-
Not wishing to touch your design (which sounds pretty dodgy), just explain this exception: A ThreadAbortException is raised within a thread when Thread.Abort is called on it. Either your code, or some framework code, must be doing that. My guess would be that the web framework kills any threads that were started as the result of a request once the request is finished, but it is just a guess – hopefully someone can post who actually knows the answer. Your posted code is swallowing exceptions – and it also appears to be using exceptions as part of normal code flow control, which is probably worse.
Thank for reply. This is not based on web request process. This is schedule based background work. the user can update the time of the scheduling from web page. on the application host the thread initiate the process.At beginning the thread started and waiting for that particular schedule time( which is getting from database)And that thread is waiting until that time using manualResetevent ( block the thread process using waitOne(milSec). If comes at the particular times, the process is read the xml file and that data would be updated to database. for that xml reading
XmlDocument configDoc = new XmlDocument();
XmlNode parentNode = null;
configDoc.Load(tConfigfilePath);
if (null != configDoc)
{
XmlNode Id = configDoc.SelectSingleNode("/CCC/AAA");
// Here the value set to object. which is datamember class.
Id.SetValue("ZZZ", detectOid.InnerText);}
Then that value inserted to database. Again that waiting for next day time using below code. In between time if any changed happened on the xml file, suddenly the catch ( with in a while loop) is catch the exception.
private void XMlreaderProcess()
{
long delayTimeSpanTicks = 0;try { while (Active) { try { triggerCtrl.Reset(); if (delayTimeSpanTicks == 0) { triggerCtrl.WaitOne(); } else { triggerCtrl.WaitOne(new TimeSpan(delayTimeSpanTicks)); } StartProcess(); } catch(Exception ex) { delayTimeSpanTicks = 0; } finally { } } } catch(Exception ex) { } finally { Active= false; }