0

如果我在我的program.cs中有以下'工作流生命週期事件'。工作流(WF)生命週期事件

無法理解WaitOne()會等待哪個信號到達?

Completed是否具有最高優先級或idle具有最高優先級或任何信號到達,它會收到?

app.Run(); 
syncEvent.WaitOne(); 



app.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e) 
{ 
    return PersistableIdleAction.Unload; 
}; 

app.Unloaded = delegate(WorkflowApplicationEventArgs e) 
{ 
    Console.WriteLine("Workflow {0} Unloaded.", e.InstanceId); 
    syncEvent.Set(); 
}; 


app.Completed = delegate(WorkflowApplicationCompletedEventArgs e) 
{ 
    if (e.CompletionState == ActivityInstanceState.Faulted) 
    { 
     Console.WriteLine("Workflow {0} Terminated.", e.InstanceId); 
     Console.WriteLine("Exception: {0}\n{1}", 
      e.TerminationException.GetType().FullName, 
      e.TerminationException.Message); 
    } 
    else if (e.CompletionState == ActivityInstanceState.Canceled) 
    { 
     Console.WriteLine("Workflow {0} Canceled.", e.InstanceId); 
    } 
    else 
    { 
     Console.WriteLine("Workflow {0} Completed.", e.InstanceId); 
    } 
}; 

app.Aborted = delegate(WorkflowApplicationAbortedEventArgs e) 
{ 
    Console.WriteLine("Workflow {0} Aborted.", e.InstanceId); 
    Console.WriteLine("Exception: {0}\n{1}", 
     e.Reason.GetType().FullName, 
     e.Reason.Message); 
}; 

app.Idle = delegate(WorkflowApplicationIdleEventArgs e) 
{ 
    Console.WriteLine("Workflow {0} Idle.", e.InstanceId); 
}; 

app.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e) 
{ 
    Console.WriteLine("OnUnhandledException in Workflow {0}\n{1}", 
     e.InstanceId, e.UnhandledException.Message); 

    Console.WriteLine("ExceptionSource: {0} - {1}", 
     e.ExceptionSource.DisplayName, e.ExceptionSourceInstanceId); 
    return UnhandledExceptionAction.Terminate; 
}; 

回答

1

你的 「卸載」 事件處理程序:

syncEvent.Set(); 

,將讓等待繼續。

事件沒有優先級,您可以按照它們發生的順序獲取它們。

+0

syncEvent.Set() - 根據我的理解,這設置事件的狀態爲發信號,允許一個或多個等待線程繼續。它將如何繼續等待? – immirza

+0

您的主線程調用syncEvent.WaitOne(),並且它在那裏等待,直到另一個線程調用允許主線程繼續執行的syncEvent.Set()。 –