online discount medstore
advair diskus for sale
buy advair diskus without prescription
allegra for sale
buy allegra without prescription
aristocort for sale
buy aristocort without prescription
astelin for sale
buy astelin without prescription
atarax for sale
buy atarax without prescription
benadryl for sale
buy benadryl without prescription
buy clarinex without prescription
clarinex for sale
buy claritin without prescription
claritin for sale
buy flonase without prescription
flonase for sale
buy ventolin without prescription
ventolin for sale
amoxil for sale
buy amoxil without prescription
augmentin for sale
buy augmentin without prescription
bactrim for sale
buy bactrim without prescription
biaxin for sale
buy biaxin without prescription
buy cipro without prescription
cipro for sale
buy cleocin without prescription
cleocin for sale
buy dexone without prescription
dexone for sale
buy flagyl without prescription
flagyl for sale
buy levaquin without prescription
levaquin for sale
buy omnicef without prescription
omnicef for sale
amaryl for sale
buy amaryl without prescription
buy cozaar without prescription
cozaar for sale
buy diabecon without prescription
diabecon for sale
buy glucophage without prescription
glucophage for sale
buy glucotrol without prescription
glucotrol for sale
buy glucovance without prescription
glucovance for sale
buy micronase without prescription
micronase for sale
buy prandin without prescription
prandin for sale
buy precose without prescription
precose for sale
buy cialis professional without prescription
cialis professional for sale
buy cialis soft without prescription
cialis soft for sale
buy cialis super active without prescription
cialis super active for sale
buy cialis without prescription
cialis for sale
buy levitra without prescription
levitra for sale
buy viagra professional without prescription
viagra professional for sale
buy viagra soft without prescription
viagra soft for sale
buy viagra super active without prescription
viagra super active for sale
buy viagra super force without prescription
viagra super force for sale
buy viagra without prescription
viagra for sale
buy celebrex without prescription
celebrex for sale
buy colcrys without prescription
colcrys for sale
buy feldene without prescription
feldene for sale
buy imitrex without prescription
imitrex for sale
buy inderal without prescription
inderal for sale
buy indocin without prescription
indocin for sale
buy naprosyn without prescription
naprosyn for sale
buy pletal without prescription
pletal for sale
buy robaxin without prescription
robaxin for sale
buy voltaren without prescription
voltaren for sale
19th Dec, 2006

Hosting Windows Workflow Foundation in a NT/Windows Service

I recently wrote an application which I needed to have run every few hours. I decided that it would run as an NT service but didn’t want to write the code to persist and load application state and deal with scheduling execution of the app.

I decided to use WF since it takes care of those requirements for me but I couldn’t find a sample where it had been hosted in a NT/Windows service. So here is an example and walk through of how to do so.

First, you’ll need to create a Windows Service application. There are a few non-WF specific steps here to get an NT service up and running.

  • Change [assembly: ComVisible(false)] to [assembly: ComVisible(true)]
  • Write an Installer class which is invoked by InstallUtil.exe to register the service

I deleted the default Program.cs the Windows Service template creates and moved the Main() method to the Service Definition. For ease of debugging, I’ve also modified it to run from the console.

Ok, lets get to hosting WF.

First, we’ll scope the workflow runtime to the lifetime of the service:

public partial class Service1 : ServiceBase

{

  WorkflowRuntime WFRT = new WorkflowRuntime();

  static void Main(string[] args)

 

 

In the Service OnStart() method, you’ll notice this line of code:

protected override void OnStart(string[] args)

{

  ThreadPool.QueueUserWorkItem(new WaitCallback(RunWorkflow),args);

}

A Windows Service requires that OnStart() return fairly quickly and if you’re creating of a number of workflow instances it can take more time than the service allows. Thus I use QueueUserWorkItem with the callback specified below. For a single workflow instance, this is a bit heavy handed, but still a good practice.

public void RunWorkflow(object obj)

{

  WorkflowInstance instance = WFRT.CreateWorkflow(typeof(Workflow1));

  instance.Start();

}

 

This is now going to kick off a very simple workflow, which every 5 seconds will write a simple message to the event log. You can find the code for this project here.

Leave a response

Your response: