Luhur S Nugroho

Windows Workflow Specialist
See also: Other Geeks@INDC

Synchronous Workflow Thread with ASP.Net

Pada acara 2nd MSDN Day beberapa waktu lalu, dengan topik Windows Workflow Architecture Pak Irving H, menjelaskan betapa susahnya mencari referensi tentang Windows Workflow. Pak Irving menjelaskan bagaimana hosting workflow di ASP.Net (IIS). Disini saya akan menjelaskan juga bagaimana hosting workflow untuk project yang saat ini saya kerjakan.

Seperti yang telah kita ketahui, ASP.Net memberikan response ketika ada request. Padahal secara default workflow dieksekusi dengan cara asychronous, sehingga ada kemungkinan response yang diberikan mendahului eksekusi workflow. Windows Workflow release terbaru (bukan beta) sudah menyediakan service agar eksekusi workflow dijalankan dengan cara synchronous.Service tersebut adalah ManualWorkflowSchedulerService.

ManualWorkflowSchedulerService adalah service workflow yang menyediakan "threading service" sehingga host menyumbangkan thread untuk instance workflow yang dipanggil. Dengan kondisi ini host dapat menjalankan instance suatu workflow dalam satu thread (synchronous), karena service ini akan memblok eksekusi host sampai instance suatu workflow menjadi idle.

Berikut cuplikan code dari global.asax

void Application_Start(object sender, EventArgs e)

{

// Code that runs on application startup

WorkflowRuntime workflowRuntime = new WorkflowRuntime("WorkflowRuntime");

ManualWorkflowSchedulerService scheduleService = new ManualWorkflowSchedulerService(true);

workflowRuntime.AddService(scheduleService);

...

workflowRuntime.StartRuntime();

Application["WorkflowRuntime"] = workflowRuntime;

}

pertama kali membuat container workflow dengan cara instance WorkflowRuntime. Tambahkan service ManualWorkflowSchedulerService kedalam WorkflowRuntime. Setelah itu jalankan runtime dari container workflowruntime. Dan workflowruntime disimpan di state application sehingga bisa dipanggil dari page-page aspx.



void Application_End(object sender, EventArgs e)

{

// Code that runs on application shutdown

WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"] as WorkflowRuntime;

...

// stop workflow runtime

workflowRuntime.StopRuntime();

}

Karena menjalankan workflowruntime pada saat application start, maka pada application stop atau IIS Stop workflow runtime perlu distop sehingga bisa menghemat memori.

Beberapa service-service workflow yang lain tidak saya cantumkan dan jelaskan saat ini, dan akan saya bahas berikutnya.

Share this post: | | | |
Posted: Oct 04 2007, 04:09 AM by luhur | with no comments
Filed under:

Comments

No Comments