online prescription solutions
online discount medstore
pills online
buy lorazepam without prescription
xanax for sale
buy xanax without prescription
buy ambien without prescription
ambien for sale
buy modafinil without prescription
buy phentermine without prescription
modafinil for sale
phentermine for sale
lorazepam for sale
buy lexotan without prescription
bromazepam for sale
xenical for sale
buy stilnox without prescription
valium for sale
buy prosom without prescription
buy mefenorex without prescription
buy sildenafil citrate without prescription
buy adipex-p without prescription
librium for sale
buy restoril without prescription
buy halazepam without prescription
cephalexin for sale
buy zoloft without prescription
buy renova without prescription
renova for sale
terbinafine for sale
dalmane for sale
buy lormetazepam without prescription
nobrium for sale
buy klonopin without prescription
priligy dapoxetine for sale
buy prednisone without prescription
buy aleram without prescription
buy flomax without prescription
imovane for sale
adipex-p for sale
buy niravam without prescription
seroquel for sale
carisoprodol for sale
buy deltasone without prescription
buy diazepam without prescription
zopiclone for sale
buy imitrex without prescription
testosterone anadoil for sale
buy provigil without prescription
sonata for sale
nimetazepam for sale
buy temazepam without prescription
buy xenical without prescription
buy famvir without prescription
buy seroquel without prescription
rivotril for sale
acyclovir for sale
loprazolam for sale
buy nimetazepam without prescription
buy prozac without prescription
mogadon for sale
viagra for sale
buy valium without prescription
lamisil for sale
camazepam for sale
zithromax for sale
buy clobazam without prescription
buy diflucan without prescription
modalert for sale
diflucan for sale
buy alertec without prescription
buy zyban without prescription
buy serax without prescription
buy medazepam without prescription
buy imovane without prescription
mefenorex for sale
lormetazepam for sale
prednisone for sale
ativan for sale
buy alprazolam without prescription
buy camazepam without prescription
buy nobrium without prescription
mazindol for sale
buy mazindol without prescription
buy mogadon without prescription
buy terbinafine without prescription
diazepam for sale
buy topamax without prescription
cialis for sale
buy tafil-xanor without prescription
buy librium without prescription
buy zithromax without prescription
retin-a for sale
buy lunesta without prescription
serax for sale
restoril for sale
stilnox for sale
lamotrigine 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: