WorkflowApplication.Run Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Commence ou reprend l’exécution d’une instance de workflow.
Surcharges
| Nom | Description |
|---|---|
| Run() |
Commence ou reprend l’exécution d’une instance de workflow. |
| Run(TimeSpan) |
Commence ou reprend l’exécution d’une instance de workflow à l’aide de l’intervalle de délai d’attente spécifié. |
Remarques
Appelez cette méthode pour lancer l’exécution d’une instance de workflow nouvellement créée.
Run()
Commence ou reprend l’exécution d’une instance de workflow.
public:
void Run();
public void Run();
member this.Run : unit -> unit
Public Sub Run ()
Exemples
L’exemple suivant héberge un workflow à l’aide de WorkflowApplication. Une WorkflowApplication instance est construite à l’aide de la définition de flux de travail spécifiée, les événements de cycle de vie de flux de travail souhaités sont gérés et le flux de travail est appelé avec un appel à Run. Une fois le flux de travail terminé, la sortie suivante s’affiche dans la console.
Starting the workflow.
Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Idle.
Ending the workflow.
Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Completed
Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Unloaded.
Activity wf = new Sequence
{
Activities =
{
new WriteLine
{
Text = "Starting the workflow."
},
new Delay
{
Duration = TimeSpan.FromSeconds(5)
},
new WriteLine
{
Text = "Ending the workflow."
}
}
};
// Create a WorkflowApplication instance.
WorkflowApplication wfApp = new WorkflowApplication(wf);
// Subscribe to any desired workflow lifecycle events.
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
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
return UnhandledExceptionAction.Terminate;
};
// Run the workflow.
wfApp.Run();
Remarques
Appelez cette méthode pour lancer l’exécution d’une instance de workflow nouvellement créée.
Si l’opération d’exécution ne se termine pas dans les 30 secondes, une TimeoutException opération est levée.
S’applique à
Run(TimeSpan)
Commence ou reprend l’exécution d’une instance de workflow à l’aide de l’intervalle de délai d’attente spécifié.
public:
void Run(TimeSpan timeout);
public void Run(TimeSpan timeout);
member this.Run : TimeSpan -> unit
Public Sub Run (timeout As TimeSpan)
Paramètres
- timeout
- TimeSpan
Appelez cette méthode pour lancer l’exécution d’une instance de workflow nouvellement créée.
Intervalle dans lequel l’opération d’exécution doit se terminer avant l’annulation de l’opération et levée TimeoutException .
Exemples
L’exemple suivant héberge un workflow à l’aide de WorkflowApplication. Une WorkflowApplication instance est construite à l’aide de la définition de flux de travail spécifiée, les événements de cycle de vie de flux de travail souhaités sont gérés et le flux de travail est appelé avec un appel à Run. Une fois le flux de travail terminé, la sortie suivante s’affiche dans la console.
Starting the workflow.
Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Idle.
Ending the workflow.
Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Completed
Workflow 593976e8-558d-4989-94d6-50a14b34fd7b Unloaded.
Activity wf = new Sequence
{
Activities =
{
new WriteLine
{
Text = "Starting the workflow."
},
new Delay
{
Duration = TimeSpan.FromSeconds(5)
},
new WriteLine
{
Text = "Ending the workflow."
}
}
};
// Create a WorkflowApplication instance.
WorkflowApplication wfApp = new WorkflowApplication(wf);
// Subscribe to any desired workflow lifecycle events.
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
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
return UnhandledExceptionAction.Terminate;
};
// Run the workflow.
wfApp.Run();
Remarques
Notez que contrairement Invokeà cette méthode, cette méthode expire uniquement si le flux de travail ne démarre pas dans la durée spécifiée, au lieu de devoir se terminer dans la durée spécifiée. La raison en est que Invoke le flux de travail s’exécute de façon synchrone (bloquant le thread hôte), tandis qu’il s’exécute de façon asynchrone, ce qui Run bloque uniquement le thread hôte pendant la durée pendant laquelle le flux de travail doit démarrer.