locked
how to pause/stop a sequential workflow at any time?

    Pertanyaan

  • hi experts,

    my system has a very long and complex workflow , sometime i need to stop it in the midle way, but current only to close the host to stop it.

    +-------------------+

    | start          |

    +------------------+

       |

    +------------------+

    |   activity 1       |

    +------------------+

     |

    +------------------+

    |  activity 2       |

    +------------------+

    .....

    i plan to use handleExternalEventActivity parallely with the sequential workflow , and sync between them.

    what's the best way to achive the goal ? 

    Thanks in advance 

    20 Februari 2012 8:02

Jawaban

  • I think you mean you want access to the WorkflowRuntime object. (http://msdn.microsoft.com/en-us/library/system.workflow.runtime.workflowruntime.aspx). 

    If you want to access the WorkflowRuntime object from a different process, you need to change the Hosting application to expose functionality of that object to other processes.

    For example, your host application can host a WCF service that exposes methods like Suspend, Terminate, etc and this service would perform call the corresponding methods on the WorkflowRuntime and would have access to the object since it lives in the same process. MSDN has a lot of information about how to implement, host and consume a WCF service. There are of other interprocess communication techniques other than WCF as well (sockets, .NET remoting, etc). 

    • Ditandai sebagai Jawaban oleh holiu 22 Februari 2012 1:27
    21 Februari 2012 13:45

Semua Balasan

  • The .NET runtime exposes some methods to control workflow.

    WorkflowInstance.Suspend() http://msdn.microsoft.com/en-us/library/system.workflow.runtime.workflowinstance.suspend.aspx 
    This method suspends the workflow without unloading it from memory. You can resume it later by calling Resume.

    WorkflowInstance.Abort() http://msdn.microsoft.com/en-us/library/system.workflow.runtime.workflowinstance.abort.aspx 
    This method unloads workflow from memory but doesn't tell the persistence service to delete the instance. If the instance was persisted in database, and loaded again from database, it will continue from the last persisted point.

    WorkflowInstance.Terminate() http://msdn.microsoft.com/en-us/library/system.workflow.runtime.workflowinstance.terminate.aspx 
    This method unloads workflow from memory and tells the persistence instance to delete the instance.

    20 Februari 2012 10:49
  • thanks. 

    further question regard this:

    how to get the workflowInstanceId from out side of the hosting application?

    i need to write a tool to monitor the workflow and its hosting app.  i can get the running hosting app on the machine as below:

                System.Diagnostics.Process[] allProcess = System.Diagnostics.Process.GetProcesses();
                System.Diagnostics.Process targetProcess = null;
                foreach (var p in allProcess)
                {
                    if (p.ProcessName.ToLowerInvariant() == hostAppName.ToLowerInvariant())
                    {
                        targetProcess = p;
                        break;
                    }
                }
    

    but how can i get the hosting app object that current running in memory associated with the targetProcess ?

    i know how to use reflection to create a new instance of the workflow hosting app, but that will give another workflowInstanceId, which is not the one i need to control.

    how to get the hosting app object from the process info ? or directlly get workflowinstanceId from it ?

    21 Februari 2012 2:44
  • I think you mean you want access to the WorkflowRuntime object. (http://msdn.microsoft.com/en-us/library/system.workflow.runtime.workflowruntime.aspx). 

    If you want to access the WorkflowRuntime object from a different process, you need to change the Hosting application to expose functionality of that object to other processes.

    For example, your host application can host a WCF service that exposes methods like Suspend, Terminate, etc and this service would perform call the corresponding methods on the WorkflowRuntime and would have access to the object since it lives in the same process. MSDN has a lot of information about how to implement, host and consume a WCF service. There are of other interprocess communication techniques other than WCF as well (sockets, .NET remoting, etc). 

    • Ditandai sebagai Jawaban oleh holiu 22 Februari 2012 1:27
    21 Februari 2012 13:45