• Visitors can check out the Forum FAQ by clicking this link. You have to register before you can post: click the REGISTER link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. View our Forum Privacy Policy.
  • Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

.NET 1.1 Exceptions during shutdown

Collapse
X
  •  
  • Filter
  • Time
  • Show
Clear All
new posts

    .NET 1.1 Exceptions during shutdown

    Grrrrr......

    Ok, I have a thread [t2] which is happily running around. This uses some objects supplied by a third party (in this case microsoft).

    Now as the app is terminated the thread [t2] gets terminated, but the objects it is using are on yet another thread [t3]. This get killed first.

    Now, the first part of the problem is that the objects dspose themselves and throw "disposed" exceptions. Thus [t2] gets an exception what it tries to access their parent object [on which there is no indication of disposed].

    So, I can esily enough code an exception handler to swallow disposed exceptions - but that is a bit too agressive. What I want to do is detect that the application is shutting down. I can't seem to find a way of detecting this :-(. [except maybe by producing an exception handler for threads and checking IsTerminaring]

    n.b. System.Environment.HasShutdownStarted is false at this point

    [I can't simply set a property somewhere myself, the application does not have a structured exit, any exit is only caused by an abort of some description]

    #2
    Hrm, you could use Thread[2].ThreadState and check to see if an abort has been requested.

    Comment


      #3
      Originally posted by Weltchy
      Hrm, you could use Thread[2].ThreadState and check to see if an abort has been requested.
      Ah, yes. That might do. I'll hack around that and see what I can come up with

      The other problem is it happens infrequently. Can't make the bugger do it now. It's timing critical.

      This leads to another question

      What I **think** is happening is:

      If thread 2 (which is a itmer callback) is not actively executing when the app exits then it's all OK

      If it is then I am surmising that:-

      - The app has asked Thread 3 to abort (the thread of the component I am using).
      - If this happens then the objects this is using get disposed but I have no way of knowing this from the available interface.
      - There is a thread switch during the execution of the code in Thread 2 (this happens to be a short piece of code on a timer callback).

      So, is there a way to block all other threads during a method [I rather imagine this would be somewhat dangerous to say the least though].
      Last edited by ASB; 11 January 2007, 10:40.

      Comment


        #4
        System.Threading.Mutex

        I think what your after is WaitOne, which means that the current thread has Mutual Exclusion over all the others.

        Comment


          #5
          Originally posted by Weltchy
          System.Threading.Mutex

          I think what your after is WaitOne, which means that the current thread has Mutual Exclusion over all the others.
          I had a skirmish around that but I couldn't figure out any way of persuading the component I am calling to use it. Time for another skirmish probably.

          Cheers,

          Comment


            #6
            With complex multithreaded apps always test your application on a single processor/single-core machine and also a multiprocessor/multi-core machine as a lot of strange errors can be found during testing that only show up on one or the other configurations.

            Comment


              #7
              Originally posted by DimPrawn
              With complex multithreaded apps always test your application on a single processor/single-core machine and also a multiprocessor/multi-core machine as a lot of strange errors can be found during testing that only show up on one or the other configurations.


              They run it on a dual core machine and all bets are definitely off.....

              Fortunately the hardware platform is very specific.

              Comment

              Working...
              X