Windows Workflow Foundation 3


Global Run Time Variable


Is there a global variable that I can use across all the workflows in my workflows?  I am loooking for what the application variable is to asp.net, but within the workflow runtime.Thanks,.Marty
Mardo  - AFAIK there isn't anything in Wf that has those sematics - but it is pretty easy to add with your own WF service.  First - define an interface (or abstract base class if you need common functionality)
public interface IWFCachingService
{
void CacheObject(string key,object o);
object GetCachedObject(string key);}
Then provide an implementation of this service (pretty easy to do with hashtable - although if you need any cache-coherency you'll need to provide locking).
public class WFCaching : IWFCachingService
{
Hashtable _cache  = new Hashtable();
public void CacheObject(string key,object o)
{
_cache[key] = o;}
public object GetCachedObject(string key)
{
return _cache[key];}
}
Then when you start the WF runtime add the service:
workflowRuntime.AddService(new WFCaching());
 
Inside of an activity you can do this:
protected override ActivityExecutionStatus Execute(ActivityExecutionContext c){
IWFCachingService cs = c.GetService<IWFCachingService>();
c.CacheObject("foo","bar");}
The responsibility for serializing the cache would lie with the workflow runtime and the host. When your host starts, it would start the runtime, then instantiate an instance of the cache and add it to the services collection for the runtime so that your workflows can have access to it. One suggestion would be to handle the WorkflowRuntime.Stopped event handler and save out the cache there, and when you are restarting the Runtime, look for this saved data so you can restore state when you start a new instance of the cache.
Does this help?Steve Danielson [Microsoft]This posting is provided "AS IS" with no warranties, and confers no rights.
 
Mardo  - AFAIK there isn't anything in Wf that has those sematics - but it is pretty easy to add with your own WF service.  First - define an interface (or abstract base class if you need common functionality)
public interface IWFCachingService
{
void CacheObject(string key,object o);
object GetCachedObject(string key);}
Then provide an implementation of this service (pretty easy to do with hashtable - although if you need any cache-coherency you'll need to provide locking).
public class WFCaching : IWFCachingService
{
Hashtable _cache  = new Hashtable();
public void CacheObject(string key,object o)
{
_cache[key] = o;}
public object GetCachedObject(string key)
{
return _cache[key];}
}
Then when you start the WF runtime add the service:
workflowRuntime.AddService(new WFCaching());
 
Inside of an activity you can do this:
protected override ActivityExecutionStatus Execute(ActivityExecutionContext c){
IWFCachingService cs = c.GetService<IWFCachingService>();
c.CacheObject("foo","bar");}
I took your advise and built the service. All seems fine, the execute get called and I get my variables.  However when the workflow dehydrates and hydrates the execute override is not being called leaving my cacheobject dead (since I can not searalize it).How can I reset my cache object on hydration?Mardo
The responsibility for serializing the cache would lie with the workflow runtime and the host. When your host starts, it would start the runtime, then instantiate an instance of the cache and add it to the services collection for the runtime so that your workflows can have access to it. One suggestion would be to handle the WorkflowRuntime.Stopped event handler and save out the cache there, and when you are restarting the Runtime, look for this saved data so you can restore state when you start a new instance of the cache.
Does this help?Steve Danielson [Microsoft]This posting is provided "AS IS" with no warranties, and confers no rights.
 
Steve,Let me be a little bit more clear. The object I am adding to the workflow services is a session factory that takes about 120 seconds to start up (somthing I only want to do once when then run time starts).  I want this to stay in the run-time.  However when I rehyderate I have no way to get it back to the workflow since it does not serialize.So Create ObjectAdd Object to ServiceStart Run TimeStart WorkFlowGetObject from serviceHyderateDeHyderateGetObjectFrom Servcice <- Im stuck hereMarty

Related Links

Windows Workflow 4
help needed in state machine workflow in asp.net
About the Role in WWF
Need suggestion of Workflow implementation
Invoking workflow from windows form
Tracking by objects
Sample unit testing project for a code activity
How to display the provider type summary in RuleSetDialog
Windows WF3.0 - get activity information from TrackingRecord object
Workflow Rules - Chaining for Indexers
WCSF PageFlow
front end
Dynamic Workflow Creation
ApplyworkflowChanges takes long time and some time crashes the application.
CLR20r3 Error when i run exe file (C#)
Process is terminated due to StackOverflowException

Categories

MSDN
Windows Desktop Develo...
Commerce Server
Data Platform Development
Microsoft Robotics
Windows Embedded Compact
SQL Server (Pre-release)
Windows Server
ScriptJunkie
Bing
Visio 2010
Microsoft Atlas API: D...
Lync Server
Archived Forums I-L
Archived Forums N-R
Kinect for Windows SDKs
Skype for Business
Maps In Windows
Where is the Forum For…?
Visual F#
Visual Studio Code Vis...
Testing with Visual St...
Visual Studio Diagnost...
Windows Desktop Develo...
Microsoft Message Queu...
Network Monitor
Windows Desktop Debugging
Windows Desktop Search...
Windows Desktop Search...
Windows Hardware WDK a...
Message Analyzer
SharePoint Legacy Vers...
Cloud Services (Web an...
Azure Networking (DNS,...
Azure Scripting and Co...
Azure Logic Apps
Language Understanding...
Azure Disk Encryption
Common Language Runtim...
Claims based access pl...
Visual FoxPro General
Software Modeling Tools
BizTalk Server RFID
ADO.NET Entity Framewo...
XML, System.Xml, MSXML...
Scripting
Small Basic
SyncFx – Microsoft Syn...
.NET Framework inside ...
SQL Server XML
SQL Server Notificatio...
SQL Server Compact
SQL Server 2012 Integr...
SQL Server 2012 PowerP...
App Linking
MSDN Magazine
Project Customization ...
Getting Started with S...
Programming Silverligh...
Report a Silverlight Bug
Expression Design
Surface Application De...
Search Server: Install...
Retired InfoPath Forms...
.NET Framework 4 Relea...
.NET Remoting and Runt...
.NET StockTrader Sampl...
Architecture Events
Crystal Reports for Vi...
Game Technologies: Aud...
Game Technologies: XNA...
Getting Started With V...
LINQ Project General
LINQ to SQL (Pre-Release)
LightSwitch HTML Clien...
Microsoft Unified Comm...
Parallel Computing Gen...
Performance Counters f...
Popfly Bugs and Sugges...
Popfly Game Creator
Parallel Programming w...
Service Bus EAI & EDI ...
Share your How to samp...
SQL Server 2014 In Azu...
SQL Server 2014 High A...
SQL Server 2014 Integr...
Tellme Studio (retired)
UI Design for Windows ...
Visual Basic Language
Visual C# Express 2008...
Visual C++ MFC and ATL
Visual Studio Database...
Visual Studio Team Sys...
Visual Studio Team Sys...
Web Gadget Development
Windows Error Reportin...
Windows MultiPoint Mou...
Building Windows Store...
Ad Revenue, Payout & T...
OneDrive Development (...
Microsoft Partner Cent...
Windows Containers
Microsoft R Server

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile