Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Thread Abort Exception

Thread Abort Exception

Scheduled Pinned Locked Moved C#
databasexmlannouncement
3 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anishkannan
    wrote on last edited by
    #1

    <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;
        }
    
    B 1 Reply Last reply
    0
    • A anishkannan

      <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;
          }
      
      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      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.

      A 1 Reply Last reply
      0
      • B BobJanova

        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.

        A Offline
        A Offline
        anishkannan
        wrote on last edited by
        #3

        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;
            }
        
        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups