app domain unloads before transaction completes commit RRS feed

  • Question

  • Hi,

    I'm working on an application that uses transaction scopes that looks something like:
    using (TransactionScope transcope = new TransactionScope(TransactionScopeOption.Required, TimeSpan.MaxValue))
          using ( MYConnection conn1 = new MyConnection() ) {
           ...do a bunch of work        
          } // end fdconn1
          using ( MYConnection conn2 = new MYConnection () ) {
           ...do a bunch of work        
          } // end fdconn2
        } // end transcope
    The MyConnection class open method Enlists the transaction via
    mySinglePhaseNotification = gcnew MySinglePhaseNotification(); 
    and MySinglePhaseNotification has the following

    void MySinglePhaseNotification::Commit(System::Transactions::Enlistment^ enlistment)
    ..Do some work
    System::Console::WriteLine("Commit Done");
    The problem I am having is when I run my app I never get the Commit Done printouts and the actual work isn't complete.  Looking under the debugger I see that MySinglePhaseNotification::Commit is run under a separate thread then the one in which the defaultAppDomain is executing.  The defaultAppDomain unloads and the process seems to terminate while the threads where the Commit is occurring are still executing.  I would have thought that the AppDomain would block and not unload until the Commit threads had completed but that simply isn't happening.  Is there anything I can do to stop the appDomain from unloading and the process exiting before my commits complete?
    Friday, October 23, 2009 12:05 AM