다음은 UI 스레드에 의해 성공적으로 시작된 새로 만든 스레드 코드입니다 (UI 코드는 여기에 없음).워크 플로 예외가 잡히지 않는 이유는 무엇입니까?
디버깅을 할 때 나는이 코드를 사용합니다.
실행중인 워크 플로에 문제가없는 경우 코드가 완료 될 때까지 실행됩니다. 그러나 워크 플로에 결함이있는 경우 (잘못된 워크 플로를 사용하여 코드를 테스트하고 있음)이 코드는 아래의 wf.Run()
문에서 발생하는 WorkflowException
을 catch하지 않습니다.
아래 워크 플로우 실행 예외 코드가 있다고 생각합니까 ?? 내가 뭘 잘못하고 있는지 말해 줄 수 있니? 감사.
public void ThreadRun()
{
AutoResetEvent syncEvent = new AutoResetEvent(false);
var wf = ActivityXamlServices.Load(fileInfo.FileName);
// Create the WorkflowApplication using the desired
// workflow definition.
WorkflowApplication wfApp = new WorkflowApplication(wf);
// Handle the desired lifecycle events.
wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
syncEvent.Set();
};
try
{
// Start the workflow.
wfApp.Run();
// Wait for Completed to arrive and signal that
// the workflow is complete.
syncEvent.WaitOne();
}
catch (Exception exception)
{
wfApp.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);
// Outputs can be retrieved from the Outputs dictionary,
// keyed by argument name.
// Console.WriteLine("The winner is {0}.", e.Outputs["Winner"]);
}
};
wfApp.Aborted = delegate(WorkflowApplicationAbortedEventArgs e)
{
// Display the exception that caused the workflow
// to abort.
Console.WriteLine("Workflow {0} Aborted.", e.InstanceId);
Console.WriteLine("Exception: {0}\n{1}",
e.Reason.GetType().FullName,
e.Reason.Message);
};
wfApp.Idle = delegate(WorkflowApplicationIdleEventArgs e)
{
// Perform any processing that should occur
// when a workflow goes idle. If the workflow can persist,
// both Idle and PersistableIdle are called in that order.
Console.WriteLine("Workflow {0} Idle.", e.InstanceId);
};
wfApp.PersistableIdle = delegate(WorkflowApplicationIdleEventArgs e)
{
// Instruct the runtime to persist and unload the workflow.
// Choices are None, Persist, and Unload.
return PersistableIdleAction.Unload;
};
wfApp.Unloaded = delegate(WorkflowApplicationEventArgs e)
{
Console.WriteLine("Workflow {0} Unloaded.", e.InstanceId);
};
wfApp.OnUnhandledException = delegate(WorkflowApplicationUnhandledExceptionEventArgs e)
{
// Display the unhandled exception.
Console.WriteLine("OnUnhandledException in Workflow {0}\n{1}",
e.InstanceId, e.UnhandledException.Message);
Console.WriteLine("ExceptionSource: {0} - {1}",
e.ExceptionSource.DisplayName, e.ExceptionSourceInstanceId);
// Instruct the runtime to terminate the workflow.
// Other choices are Abort and Cancel. Terminate
// is the default if no OnUnhandledException handler
// is present.
return UnhandledExceptionAction.Terminate;
};
}
}
그런데 예외를 잡은 후에 대리인을 설정하는 이유는 무엇입니까? ... – Qnan
try {wfApp.Run()) – user1298925
전에 대리자를 설정하려고 시도했으며 어떤 결과가 나타 났습니까? – Qnan