locked
Why application hangs when nested distributed transaction rollback? RRS feed

  • Question

  • Application hangs when distributed transaction rollback .

    This situation occures only for nested   transaction like in the example below.

    I have the next application that simplify a real situation.

    After the exception is being throw in the workflow activity (CodeActivity2) the application hangs.

    It behaves the same if I replace   throw new Exception ("CodeActivity2" ); with Transaction .Current.Rollback();

     

     
    
    static void Main(string[] args)
    
        {
    
          Console.WriteLine("Press any key.");
          Console.ReadLine();
    
          try
    
          {
            InvokeWorkflow();
          }
    
          catch (Exception ex)
    
          {
            Console.WriteLine(ex.Message);
          }
        }
    
        private static void InvokeWorkflow()
    
        {
    
          using (var scope = new TransactionScope())
    
          {
    
            var workflow = new System.Activities.Statements.TransactionScope
    
                     {
                         Body = new System.Activities.Statements.Sequence
    
                            {
                                Activities = { new CodeActivity2() }
                            }
    
                     };
    
            WorkflowInvoker.Invoke(workflow);
    
            scope.Complete();
    
          }
    
        }
      
    
        public class CodeActivity2 : CodeActivity
    
        {
            protected override void Execute(CodeActivityContext context)
    
           {
    
           using (var scope = new TransactionScope())
    
              {
    
                throw new Exception("CodeActivity2");
    
              }
    
            }
    
      }
    
    

    Monday, January 10, 2011 1:28 PM

All replies

  • Hi,

    To use the transaction. you need a transaction supported data store/IO device. for example: Sql Server.
    If there is no data write or read action happens. transaction is not really needed.

    If there is no IO action happens. The thing you need to do is adding a transistion to the previous activity when some exception happens. or just throw the exception out. no need to use a Transaction action.

    Regards


    MSDN Community Support
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    This posting is provided "AS IS" with no warranties, and confers no rights. My Blog: http://xhinker.com
    Microsoft Windows Workflow Foundation 4.0 Cookbook
    Wednesday, January 12, 2011 6:33 AM
  •  

    This is just a simplified example, of course in my real application I save data to an Sql Server.

    Wednesday, January 12, 2011 8:50 AM