Domanda

Sono stato sorpreso dall'uso corretto di ManualWorkflowSchedulerService.RunWorkflow (). Devo sincronizzare le chiamate allo stesso flusso di lavoroInstanceId tra thread quando chiamo ManualWorkflowSchedulerService.RunWorkflow?

È stato utile?

Soluzione

No, non credo. Di seguito è riportato un estratto pertinente del 'Essential Windows Workflow

  

Anche se le operazioni sono attive   WorkflowInstance può essere richiamato   thread arbitrari, lo scheduler WF   ospitato all'interno dell'istanza del programma è   assistito da un singolo thread. Il WF   runtime garantisce che nessun altro   il thread può interferire o servire il   scheduler mentre è il suo loop dispatcher   elaborare attivamente gli elementi di lavoro. Essere   chiaro, l'applicazione di hosting può   invocare metodi di WorkflowInstance su   thread separati contemporaneamente - questo   non influisce sullo scheduler   eseguire le attività su a   thread dedicato (per un episodio di   esecuzione).


EDIT: per approfondire il problema, ho creato un file wf con un ParallelActivity che contiene due attività HandleExternalEvent . Il gestore invocato di ogni attività mette semplicemente in pausa il thread per 3 secondi. Nel programma host ho creato due thread e attivato i due eventi tramite il servizio. Inoltre, eseguo la sottoclasse del ManualWorkflowSchedulerService per tenere traccia del metodo Schedule . Ecco i risultati (il tempo è in decimi di ms):

Src    Time Thread
HOST   7616      1 CreateWorkflow
MWSS   7642      1 Schedule workflow
HOST   8297     12 Trigger event 1 and wait for RunWorkflow
MWSS   8316     12 Schedule workflow
  WF   8327     12 Handler 1 Invoked...wait 3 sec
HOST   8327      1 Press any key to exit...
HOST   8767     13 Trigger event 2 and wait for RunWorkflow
MWSS   8784     13 Schedule workflow
  WF  38319     12 Handler 1 Completed
  WF  38406     12 Handler 2 Invoked...wait 3 sec
  WF  68396     12 Handler 2 Completed
HOST  68573     13 RunWorkflow for event 2 completed in 5,98 sec
HOST  68794     12 WorkflowCompleted
HOST  68795     12 RunWorkflow for event 1 completed in 6,05 sec

Alcune osservazioni:

  1. Lo scheduler usa sempre il thread dell'host per pianificare il workitem.
  2. L'istanza del flusso di lavoro non sempre utilizza il thread dell'host per eseguire le attività. Se un'altra attività è già in esecuzione in un thread, questo thread viene utilizzato per eseguire tutte le attività pianificate.
  3. L'esecuzione dei gestori è sicura per i thread, ma entrambi i thread attendono il completamento di entrambi i gestori!

Se la tua preoccupazione è quest'ultima, suggerirei i seguenti post:

A proposito, puoi condividere alcune informazioni sullo scenario che stai affrontando?

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top