none
need to pause and resume workflow RRS feed

  • Question

  • hi,

    i have workflow Host Window with some button like Pause, Resume and Terminate workflow, in which single workflow is hosted.

    is there any body konw how can i pause or resume the current workflow that is hosted in my window.

    also i want to store the extra information when workflow is going to persist. like its all variables values.

    Regards,

    joyous suhas

    Monday, April 19, 2010 12:44 PM

Answers

  • Hi,Suhas

    You can manually stop workflow and persisted the running workflow by calling:

        workflowApplication.Unload();

    You can Resume a certain workflow from persistence store by calling:

        workflowApplication.Load(GUID wfInstanceID);

     

    Here is a full sample, you need to configure Sql persistence store by yourself:

     

             static string bkName = "bkName";

             static void Main(string[] args) {

                StartAndUnloadInstance();

             }

           

             static void StartAndUnloadInstance() {

                AutoResetEvent waitHandler = new AutoResetEvent(false);

                WorkflowApplication wfApp = new WorkflowApplication(GetDelayedWF());

                SqlWorkflowInstanceStore instanceStore = SetupSqlpersistenceStore();

                wfApp.InstanceStore = instanceStore;

                wfApp.Extensions.Add(SetupMyFileTrackingParticipant);

                wfApp.PersistableIdle = (e) => {          ///persists application state and remove it from memory

                    return PersistableIdleAction.Unload;

                };

                wfApp.Unloaded = (e) => {

                    waitHandler.Set();

                };

                Guid id = wfApp.Id;

                wfApp.Run();

                waitHandler.WaitOne();

                LoadAndCompleteInstance(id);

            }

     

           

           static void LoadAndCompleteInstance(Guid id) {         

                Console.WriteLine("Press <enter> to load the persisted workflow");

                Console.ReadLine();

                AutoResetEvent waitHandler = new AutoResetEvent(false);

                WorkflowApplication wfApp = new WorkflowApplication(new Workflow1());

                wfApp.InstanceStore =

                    new SqlWorkflowInstanceStore(ConfigurationManager.AppSettings["SqlWF4PersistenceConnectionString"].ToString());

                wfApp.Completed = (workflowApplicationCompletedEventArgs) => {

                    Console.WriteLine("\nWorkflowApplication has Completed in the {0} state.",

                                      workflowApplicationCompletedEventArgs.CompletionState);

                };

                wfApp.Unloaded = (workflowApplicationEventArgs) => {

                    Console.WriteLine("WorkflowApplication has Unloaded\n");

                    waitHandler.Set();

                };

                wfApp.Load(id);

                wfApp.Run();

                waitHandler.WaitOne();

            }

           

           

            public static Activity GetDelayedWF() {

                return new Sequence {

                    Activities ={

                        new WriteLine{Text="Workflow Started"},

                        new Delay{Duration=TimeSpan.FromSeconds(10)},

                        new WriteLine{Text="Workflow Ended"}

                    }

                };

            }

            

     

     

            private static SqlWorkflowInstanceStore SetupSqlpersistenceStore() {

     

                string connectionString = ConfigurationManager.AppSettings["SqlWF4PersistenceConnectionString"].ToString();

                SqlWorkflowInstanceStore sqlWFInstanceStore = new SqlWorkflowInstanceStore(connectionString);

                sqlWFInstanceStore.InstanceCompletionAction = InstanceCompletionAction.DeleteAll;

                InstanceHandle handle = sqlWFInstanceStore.CreateInstanceHandle();

                InstanceView view = sqlWFInstanceStore.Execute(handle, new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(5));

                handle.Free();

                sqlWFInstanceStore.DefaultInstanceOwner = view.InstanceOwner;

                return sqlWFInstanceStore;

            }

     

    Hope it helps

    Regards


    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support
    Monday, April 26, 2010 2:59 AM
    Moderator

All replies

  • I have the same question.

     

    Wednesday, April 21, 2010 7:01 PM
  • Hi,Suhas

    You can manually stop workflow and persisted the running workflow by calling:

        workflowApplication.Unload();

    You can Resume a certain workflow from persistence store by calling:

        workflowApplication.Load(GUID wfInstanceID);

     

    Here is a full sample, you need to configure Sql persistence store by yourself:

     

             static string bkName = "bkName";

             static void Main(string[] args) {

                StartAndUnloadInstance();

             }

           

             static void StartAndUnloadInstance() {

                AutoResetEvent waitHandler = new AutoResetEvent(false);

                WorkflowApplication wfApp = new WorkflowApplication(GetDelayedWF());

                SqlWorkflowInstanceStore instanceStore = SetupSqlpersistenceStore();

                wfApp.InstanceStore = instanceStore;

                wfApp.Extensions.Add(SetupMyFileTrackingParticipant);

                wfApp.PersistableIdle = (e) => {          ///persists application state and remove it from memory

                    return PersistableIdleAction.Unload;

                };

                wfApp.Unloaded = (e) => {

                    waitHandler.Set();

                };

                Guid id = wfApp.Id;

                wfApp.Run();

                waitHandler.WaitOne();

                LoadAndCompleteInstance(id);

            }

     

           

           static void LoadAndCompleteInstance(Guid id) {         

                Console.WriteLine("Press <enter> to load the persisted workflow");

                Console.ReadLine();

                AutoResetEvent waitHandler = new AutoResetEvent(false);

                WorkflowApplication wfApp = new WorkflowApplication(new Workflow1());

                wfApp.InstanceStore =

                    new SqlWorkflowInstanceStore(ConfigurationManager.AppSettings["SqlWF4PersistenceConnectionString"].ToString());

                wfApp.Completed = (workflowApplicationCompletedEventArgs) => {

                    Console.WriteLine("\nWorkflowApplication has Completed in the {0} state.",

                                      workflowApplicationCompletedEventArgs.CompletionState);

                };

                wfApp.Unloaded = (workflowApplicationEventArgs) => {

                    Console.WriteLine("WorkflowApplication has Unloaded\n");

                    waitHandler.Set();

                };

                wfApp.Load(id);

                wfApp.Run();

                waitHandler.WaitOne();

            }

           

           

            public static Activity GetDelayedWF() {

                return new Sequence {

                    Activities ={

                        new WriteLine{Text="Workflow Started"},

                        new Delay{Duration=TimeSpan.FromSeconds(10)},

                        new WriteLine{Text="Workflow Ended"}

                    }

                };

            }

            

     

     

            private static SqlWorkflowInstanceStore SetupSqlpersistenceStore() {

     

                string connectionString = ConfigurationManager.AppSettings["SqlWF4PersistenceConnectionString"].ToString();

                SqlWorkflowInstanceStore sqlWFInstanceStore = new SqlWorkflowInstanceStore(connectionString);

                sqlWFInstanceStore.InstanceCompletionAction = InstanceCompletionAction.DeleteAll;

                InstanceHandle handle = sqlWFInstanceStore.CreateInstanceHandle();

                InstanceView view = sqlWFInstanceStore.Execute(handle, new CreateWorkflowOwnerCommand(), TimeSpan.FromSeconds(5));

                handle.Free();

                sqlWFInstanceStore.DefaultInstanceOwner = view.InstanceOwner;

                return sqlWFInstanceStore;

            }

     

    Hope it helps

    Regards


    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support
    Monday, April 26, 2010 2:59 AM
    Moderator
  • ->"also i want to store the extra information when workflow is going to persist. like its all variables values."

    You can store extra information by using PersistenceParticipant, check this:

    http://msdn.microsoft.com/en-us/library/ee473464(v=VS.100).aspx


    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support
    Monday, April 26, 2010 3:08 AM
    Moderator
  • What if I just want to stop execution (and resume later) without persisting to a database?
    Friday, January 21, 2011 8:39 AM