WorkflowRuntime.StartRuntime Metode

Definisi

Memulai mesin run-time alur kerja dan layanan mesin run-time alur kerja.

public:
 void StartRuntime();
public void StartRuntime ();
member this.StartRuntime : unit -> unit
Public Sub StartRuntime ()

Pengecualian

Ada lebih dari satu layanan alur CommitWorkBatch kerja layanan yang terdaftar dengan ini WorkflowRuntime.

-atau-

Ada lebih dari satu layanan penjadwal yang terdaftar dengan ini WorkflowRuntime.

-atau-

Ada lebih dari satu layanan persistensi yang terdaftar dengan ini WorkflowRuntime.

Contoh

Contoh kode berikut menunjukkan cara menggunakan WorkflowRuntime fungsionalitas dari host alur kerja. Kode memanggil StartRuntime setelah WorkflowRuntime membuat instans WorkflowRuntime dan setelah memanggil AddService untuk menambahkan layanan ke runtime. Ini juga memanggil StartRuntime sebelum pemrosesan lain terjadi.

Contoh kode ini adalah bagian dari sampel Membatalkan Alur Kerja .

static void Main()
{
    string connectionString = "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;";

    using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
    {
        ExternalDataExchangeService dataService = new ExternalDataExchangeService();
        workflowRuntime.AddService(dataService);
        dataService.AddService(expenseService);

        workflowRuntime.AddService(new SqlWorkflowPersistenceService(connectionString));
        workflowRuntime.StartRuntime();

        workflowRuntime.WorkflowCompleted += OnWorkflowCompleted;
        workflowRuntime.WorkflowTerminated += OnWorkflowTerminated;
        workflowRuntime.WorkflowIdled += OnWorkflowIdled;
        workflowRuntime.WorkflowAborted += OnWorkflowAborted;

        Type type = typeof(SampleWorkflow1);
        WorkflowInstance workflowInstance = workflowRuntime.CreateWorkflow(type);
        workflowInstance.Start();

        waitHandle.WaitOne();

        workflowRuntime.StopRuntime();
    }
}
Shared Sub Main()
    Dim connectionString As String = "Initial Catalog=SqlPersistenceService;Data Source=localhost;Integrated Security=SSPI;"
    Using workflowRuntime As New WorkflowRuntime()
        Dim dataService As New ExternalDataExchangeService()
        workflowRuntime.AddService(dataService)
        dataService.AddService(expenseService)

        workflowRuntime.AddService(New SqlWorkflowPersistenceService(connectionString))


        AddHandler workflowRuntime.WorkflowCompleted, AddressOf OnWorkflowCompleted
        AddHandler workflowRuntime.WorkflowTerminated, AddressOf OnWorkflowTerminated
        AddHandler workflowRuntime.WorkflowIdled, AddressOf OnWorkflowIdled
        AddHandler workflowRuntime.WorkflowAborted, AddressOf OnWorkflowAborted


        Dim workflowInstance As WorkflowInstance
        workflowInstance = workflowRuntime.CreateWorkflow(GetType(SampleWorkflow))
        workflowInstance.Start()

        waitHandle.WaitOne()

        workflowRuntime.StopRuntime()
    End Using
End Sub

Keterangan

Metode ini memverifikasi bahwa sekumpulan layanan inti yang valid ada dan kemudian memulai layanan apa pun yang berasal dari WorkflowRuntimeService kelas . Harus ada satu dan hanya satu dari masing-masing layanan inti berikut: layanan alur CommitWorkBatch kerja yang berasal dari WorkflowCommitWorkBatchService kelas dasar dan layanan penjadwal yang berasal dari WorkflowSchedulerService kelas dasar. Jika salah satu atau kedua layanan inti ini hilang, mesin run-time alur kerja menyediakan layanan default yang sesuai: DefaultWorkflowCommitWorkBatchService untuk layanan alur CommitWorkBatch kerja dan DefaultWorkflowSchedulerService untuk layanan penjadwal. Layanan persistensi bersifat opsional, tetapi mungkin hanya ada satu layanan persistensi yang ada. Setelah memvalidasi konfigurasi layanan, StartRuntime panggilan Start pada semua layanan yang berasal dari WorkflowRuntimeService kelas . Terakhir, alur kerja menjalankan set IsStarted mesin run-time dan meningkatkan Started peristiwa.

Anda tidak dapat menambahkan atau menghapus layanan inti setelah mesin run-time alur kerja dimulai. Layanan inti adalah layanan yang berasal dari WorkflowSchedulerService kelas, WorkflowCommitWorkBatchService kelas, WorkflowPersistenceService kelas , atau TrackingService kelas . Jika Anda memanggil StartRuntime saat mesin run-time alur kerja berjalan, tidak ada tindakan yang dilakukan.

Berlaku untuk