Experimenting with Memory for AutoStart SPWorkflow
Published 11/29 courtesy of Bamboo Solutions Community
When a SharePoint workflow is started through the Web client, the workflow is loaded in the memory of w3wp.exe until the workflow becomes idle and dehydrates to the SharePoint database. When the same workflow instance is rehydrated again, it is loaded in owstimer.exe. A SharePoint workflow can be started manually or it can be automatically started when an item is added or an existing item is changed in a list or a document library. Regardless of how a workflow is started, I always thought the memory management for loading a SharePoint workflow should be similar to what is stated above.
Some time ago, one of my colleagues, Jonas Nilsson, asked me that if a console application adds an item to a list, could the automatically started workflow on that list get loaded in the console application's memory? My first reaction was that this wouldn't be possible because the console application is not hosting the workflow, but is simply adding items to the list. I was counting on the timer service to load and run the workflow in this case. Well, experimentation showed that the timer service is not the hard working fellow in this case.
I wrote a few lines in a console application to add a file to a shared documents library which automatically started a workflow when an item was added to the library:
string destUrl = "http//somesite"; site = new SPSite(destUrl).OpenWeb(); byte[] contents = new byte[1]; contents[0] = 0; SPFileCollection sfc = site.GetFolder("Shared Documents").Files; destUrl = sfc.Folder.Url + "/" + "test1.txt"; sfc.Add(destUrl, contents,true);
The result? The item was added to the list, but the workflow was not triggered.
I then modified the code adding a line, Console.ReadLine(), at the end to pause the console application until some user input had been received:
string destUrl = "http//somesite"; site = new SPSite(destUrl).OpenWeb(); byte[] contents = new byte[1]; contents[0] = 0; SPFileCollection sfc = site.GetFolder("Shared Documents").Files; destUrl = sfc.Folder.Url + "/" + "test2.txt"; sfc.Add(destUrl, contents,true); Console.ReadLine(); // this is added to pause the console application.The result? If the user does not type any input into the application, the item is added, the workflow is triggered, and begins running.
The SharePoint log file logged two entries in the second experienment:
11/17/2010 22:51:30.73 ConsoleAddFileToList.vshost.exe (0x030C) 0x1390 SharePoint Foundation Monitoring b4ly High Leaving Monitored Scope (FireWorkflowStartingEvent). Execution Time=1.61752401492368
11/17/2010 22:51:37.26 ConsoleAddFileToList.vshost.exe (0x030C) 0x1390 SharePoint Foundation Monitoring b4ly High Leaving Monitored Scope (Event Receiver (Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, Microsoft.SharePoint.Workflow.SPWorkflowAutostartEventReceiver)). Execution Time=8071.44958367614
As you can see, the firing of the workflow start event and event receiver all happened in the console application's process.
In addition, Visual Studio showed that the workflow template dll was indeed loaded in the console application's memory:
Conclusion: When writing a console application or other short-lived process to add or change an item in a SharePoint list or document library, be aware that the automatically started workflow may not have a chance to start because the process it is supposed to be loaded into may have finished running too quickly. I am starting to wonder whether some of the event firing and event receivers in SharePoint follow a similar memory process.
Recent SharePoint Questions
- sharepoint Q&A function
- Customize "Send To" menu in Sharepoint 2007
- Site is opening only on Server but not on other clients. How to fix this?
- Handy & Free of Charge SharePoint Tools
- One Document - two sites
- What is the difference between a document library and a form library?
- What is Collaborative Application Markup Language?
- • What is the difference between SharePoint Portal Server and Windows SharePoint Services?
- Why should you use SharePoint?
- Displaying columns
more sharepoint questions
More Articles By
Develop Mobile Applications for SharePoint with Mobile Entree - CMSWire
Develop Mobile Applications for SharePoint with Mobile Entree
CMSWire, CA
By Barb Mosher | Jun 5, 2009 Seeing as how SharePoint (news, site) is so widely used within the enterprise today, it's…
Bamboos Year in Review: Marc OBrien Introduces the Bamboo Online Applications Division
Editor's note: Last year we introduced the Bamboo Year in Review feature, kicking off with a note
While writing the final sentences of my post on how to create a SharePoint blog last week, I realized that I needed to circle back and spend some time… Mobile Entrée is installed as a SharePoint solution and is deployed as a series of features.
Top News Stories Make your plans now to attend the Best Practices Conference this August 24-26 in Washington, D.C. to ensure that you don't miss out on sessions presented by some…Working with the Admin Links on your SharePoint Blog
More Articles Under "News from Around the Web"
Guest Blog by H3 Solutions Jason Hall - Mobile Entrée, Taking a Look Under the Hood
SharePoint on Your SmartPhone, Android Moves to Laptops, Best Practices Conference Speakers List
Google Wave - A Developer's Eye View (The Register)
Last week, Google announced Wave, a…Announcing the Best Practices Conference Speakers List!
Most Viewed Content

