Geeks With Blogs
Tanveer Ibn Haresh
Source Code:MSDN
In previous versions, application used to get reference to Current workflowrutime by using codes like this:

WorkflowRuntime workflowRuntime=WorkflowRequest.Current.WorkflowRuntime;

But with 3.5 web applications use application object to store the workflowRuntime when the application starts and disposes of the runtime instance when the application stops. Global.asax file is used to hook the application_start and Application_End Event.

Here is how it is done:

void Application_Start(object sender, EventArgs e)
{
    System.Workflow.Runtime.WorkflowRuntime workflowRuntime =
        new System.Workflow.Runtime.WorkflowRuntime();

    System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService manualService =
        new System.Workflow.Runtime.Hosting.ManualWorkflowSchedulerService();
    workflowRuntime.AddService(manualService);
   
    workflowRuntime.StartRuntime();

    Application["WorkflowRuntime"] = workflowRuntime;          
}

void Application_End(object sender, EventArgs e)
{
    System.Workflow.Runtime.WorkflowRuntime workflowRuntime =
        Application["WorkflowRuntime"] as System.Workflow.Runtime.WorkflowRuntime;
    workflowRuntime.StopRuntime();
}

This workFlowRuntime instance remains in the application object as long as the webapplication handles requests.
Here is how you can how to retrieve this workflow runtime instance from the application object and star a workflow successfully.

protected void StartRuntime_Click(object sender, EventArgs e)
{
    WorkflowRuntime workflowRuntime = Application["WorkflowRuntime"] as WorkflowRuntime;
    ManualWorkflowSchedulerService manualScheduler =
        workflowRuntime.GetService(typeof(ManualWorkflowSchedulerService))
        as ManualWorkflowSchedulerService;

    WorkflowInstance instance = workflowRuntime.CreateWorkflow(
        typeof(ASPNetSequentialWorkflow));
    instance.Start();
    manualScheduler.RunWorkflow(instance.InstanceId);
} Posted on Wednesday, February 4, 2009 12:49 PM WorkFlow | Back to top


Comments on this post: Making sure Workflow Runtime has a single instance in the WebApplication Runtime

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Great post. I wish more people had simple and direct posts as yours.

Thanks :)
Left by Omid on Apr 22, 2009 2:31 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
This is wonderful article ...it would be great if u can share...how to proceed with state m/c workflow with asp.net..

Regards
Farooque
Left by FAROOQUE NM on Jul 20, 2009 5:12 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Thanks for sharing these info with us! I was reading something similar on another website that i was researching. I will be sure to look around more. thanks...
Left by teeth whitener on Aug 11, 2009 8:01 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Apollo is a cross-platform runtime library that is available for Windows (XP SP2 or Vista) and Mac OS X 10.4 or higher—a Linux version is also in the works, but is not yet available. The runtime allows developers to create applications using HTML (both vanilla and enhanced with AJAX), JavaScript, and Flash. These applications can then be made available as a downloadable link on a web site, which will install the application (and the appropriate operating system runtime) to the user's desktop. After that, the application can be run by double-clicking on the desktop icon, just like any other application.
Left by Truss Displays on Sep 02, 2009 2:27 AM

# Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Thanks for the information. I had no clue that the Runtime application code had been updated. Seems like a lot more code then the previous version.
Left by Outdoor Signs on Sep 02, 2009 4:23 PM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Good post very informative on the code update. Hopefully this code works with a simple update of the older code.
Left by Custom Trade Show Exhibits on Sep 03, 2009 6:22 PM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Thanks for sharing useful information i liked it alot nice post.
Left by Sex Toy Store on Oct 24, 2009 10:27 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Nice i had no clue that the Runtime application code had been updated.
Left by Porn DVD on Oct 26, 2009 5:30 PM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
This is a very valuable post.this is very good idea to start and run the workrun time at a single instance.Thanks for providing the code.By this application,the loading time can be increased and also reliable to work.
Left by uk broadband on Nov 23, 2009 4:31 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Here is how you can how to retrieve this workflow runtime instance from the application object and star a workflow successfully.
Left by Sex DVD on Nov 24, 2009 8:42 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Great post. I wish more people had simple and direct posts as yours.

Thanks
Left by Adult Novelties on Nov 26, 2009 5:22 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
nice and very informative thanks for sharing with us great post
Left by corsets on Dec 10, 2009 11:27 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Nice and thanks for given information to us.
Left by e-cigarette on Dec 13, 2009 6:54 AM

# Geeks are smart!
Requesting Gravatar...
My son is 20 and has blog he proudly calls cotygeek. I am not so crazy about the geek name, but I have a new found respect for geeks of all types. They are some very smart guys who take much pride in what they do!
Left by shopalu on Dec 15, 2009 7:09 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
I always enjoy visiting your site. The content is always informative and enjoyable to read. I even have you bookmarked. Thanks so much for the info you provide.
Left by Digital Signage on Dec 15, 2009 4:50 PM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Nice and thanks for given information to us.
Left by cigarette filter on Dec 19, 2009 12:46 PM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
You always have great interesting stuff to read. keep it up. Will be returning, thats for sure.
Left by Drug Testing on Dec 27, 2009 10:02 PM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
If you’re a developer who lives in the real world of shared hosting accounts and clients with deadlines, and if you’re tired of ponderously large and thoroughly undocumented frameworks:
Left by journal des casinos en ligne on Mar 05, 2010 4:07 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
thanks for posting it up. Very informative and useful post.
Left by fixed annuity rates on Apr 08, 2010 7:54 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Thanks. It was worth to read
Left by Dating sites reviews on Apr 15, 2010 2:52 PM

# wsi
Requesting Gravatar...

I like this term "factory SEO". SEO project is just like any other projects...
Left by Seo Consultant Hertfordshrie on Jul 29, 2010 9:26 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Now this is what i call a real post. I wish more people had simple and direct posts like yours!

Thanks
Left by technical analysis on Aug 01, 2010 9:28 PM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Now I know why the Global.asax file is used to hook the application_start and Application_End Event.
Left by architectuur on Oct 07, 2010 11:24 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Thanks for sharing this information. It's valuable indeed for those who are interested in it.
Left by Dildo on Nov 08, 2010 4:15 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Nice post.Thanks for sharing. It would be great if you can provide more details about it.

Left by 1 hour loan on Dec 20, 2010 12:14 PM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
I really very impressed with your article. You have shared a nice technical article. I appreciate your efforts.
Left by cheap payday loans on Dec 23, 2010 1:30 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
I am really impressed with your recent blog post. I am going to bookmark your website for future references.
Left by Chicago Wrongful Death Lawyer on Mar 22, 2011 1:44 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Interesting post and thanks for sharing. Some things in here I have not thought about before.Thanks for making such a cool post which is really very well written.will be referring a lot of friends about this.Keep blogging.
Left by custom essay writing services on Mar 22, 2011 1:45 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Just want to say your article is striking. The clearness in your post is simply spectacular and i can take for granted you are an expert on this field. Thanks a million and please keep up the effective work.
Left by Small tractors on Mar 22, 2011 1:50 PM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Unlike additional blogs I have read which are really good. I also found your posts very interesting
Left by confidence on Mar 22, 2011 1:51 PM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Windows Work flow Foundation (WF) is a powerful framework for building work flow-driven applications. But WF itself is just a set of libraries that are added to the .NET Framework. There is a WF run time and a set of services, built-in activities, and the work flows and activities that you write, but those are all just classes and libraries that need. Thanks for sharing.

Left by Hoover Steamvac with clean surge on Mar 27, 2011 12:24 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
The most traditional bow ties are usually of a fixed length and are made for a specific size neck. Sizes can vary between approximately.
Left by IT Support California on Mar 28, 2011 8:23 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Very nice and helpful information has been given in this article. I must say that this is a great post. I loved reading it..
Left by Pictures of australia on Apr 04, 2011 11:38 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
These dark clouds are scaring me of the storm that have been faced by the people over there.

Left by Pictures of australia on Apr 04, 2011 11:39 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
This storm looks big from the dark clouds and this is a good pic taken at that time.
Left by kombucha mushrooms on Apr 04, 2011 11:40 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...

i'd love it ^_^ happy to see ur guys again ^_^ *hug*hug*
Left by ed hardy clothing on Jun 07, 2011 3:19 AM

# re: Making sure Workflow Runtime has a single instance in the WebApplication Runtime
Requesting Gravatar...
Boss totally technical article. You have presented the code in very good manner. workflow runtime is very much exlained.
Left by build muscles on Jul 01, 2011 12:14 PM

# re:
Requesting Gravatar...
Hi i just got a lot of information in your blog.I like it very much.I just stumble on this and got it inforamtive.
Left by Water Softeners Beaconsfield on Aug 04, 2011 5:03 AM

Your comment:
 (will show your gravatar)


Copyright © Tanveer-Ibn-Haresh | Powered by: GeeksWithBlogs.net