Windows Workflow Foundation 3


Share large data between workflow and application


 
Hi, there
My problem is that I
want to share data between the workflow and application.
Here is the problem
more simplified:
I have created a state
workflow and I have one public variable, I handle the “stateInitialization”
event and I have putted here a code activity pointing to the “InitState”
function.
 
It looks like this:
public sealed partial
class Workflow1: StateMachineWorkflowActivity
{
            public int myValue = 1;
 
            public Workflow1()
            {
                        InitializeComponent();
            }
 
            private void InitState(object
sender, EventArgs e)
            {
                        myValue
= 3;
            }
}
 
My main function
looks like this:
static void Main(string[] args)
{
            using(WorkflowRuntime
workflowRuntime = new WorkflowRuntime())
            {
                        AutoResetEvent waitHandle = new
AutoResetEvent(false);
                        workflowRuntime.WorkflowCompleted
+= delegate(object sender,                       WorkflowCompletedEventArgs e) {waitHandle.Set();};
                        workflowRuntime.WorkflowTerminated
+= delegate(object sender,                      WorkflowTerminatedEventArgs e)
                        {
                                    Console.WriteLine(e.Exception.Message);
                                    waitHandle.Set();
                        };
 
                        WorkflowInstance
instance = workflowRuntime.CreateWorkflow(typeof(WorkflowMockup.Workflow1));
 
            instance.Start();
 
            Workflow1 aWorkflow =
instance.GetWorkflowDefinition() as Workflow1;
            aWorkflow.myValue = 2;
 
           
waitHandle.WaitOne();
            }
}
 
The sequence of
execution looks goes like this:
 
myValue = 1; from the initialization.            (myValue is not set)
myValue = 2; from the
main program. (myValue is 1 before this)
And
myValue = 3; from the
InitState function, but myValue is still 1 and not 2.
 
At the first
appearance it seamed that there are two Workflow1 objects and they don’t have anything
to do with each other. Application side is one instance and workflow side is other
instance.
But this is not the
problem the problem might be that there are two threads and somehow the data
does not get synchronized.
 
To overcome this I
found two workarounds.
1. Call external
method and pass the data as a parameter.
The problem here is
that if you have large data structures than you need to pass it all. Need to
make the data serializable and need to pass as parameter.
 
2. Create a Singleton
class and put the data inside of this. This way you can get the data anywhere.
The problem with this
solution is that I personally do not like it. It is not a good design practice.
Does anybody know a
better way/design to solve this problem?
My big picture problem
is that that I want to render UI, based on Business Objects handled by
workflow.
There is no direct way to share data between the workflow and the host. From the host you cannot access directly (eg myWorkflowInstance.MyProperty) Using CallExternalMethod/HandleExternalEvent with an ExternalDataExcahnge service is the way to go. If your data is large than it may be appropriate to save it to a database and then pass a key around via the communication service. If these items that you wish to pass are owned by the workflow then you could save them as UserTrackPoints and then query the TrackingDB for them in your host application.
If these do not seem like they apply, please reply with additional details on your scenario and we will take a deeper look.
Thanks,
Steve Danielson [Microsoft]This posting is provided "AS IS" with no warranties, and confers no rights.
Use a database.
There is no direct way to share data between the workflow and the host. From the host you cannot access directly (eg myWorkflowInstance.MyProperty) Using CallExternalMethod/HandleExternalEvent with an ExternalDataExcahnge service is the way to go. If your data is large than it may be appropriate to save it to a database and then pass a key around via the communication service. If these items that you wish to pass are owned by the workflow then you could save them as UserTrackPoints and then query the TrackingDB for them in your host application.
If these do not seem like they apply, please reply with additional details on your scenario and we will take a deeper look.
Thanks,
Steve Danielson [Microsoft]This posting is provided "AS IS" with no warranties, and confers no rights.

Related Links

WorkFlowRuntime with events (ASp.Net)
Workflow on the fly
Windows Workflow and ASP.Net
State Machine "Undo" to previous state
Bind workflow property to a read-only activity property
Developing an application for a service support provider.
WorkflowRuntime.CreateWorkflow Performance
Access sequential workflow dependency property from custom activity
Access to workflow queues from external processes
Persiste in a custom activity
Workflow re-activates on Final State when using OnWorkflowItemChanged Event
Windows WorkFlow Foundation: Cannot add a new state in between two existing states.
Within VS2008, can't drill down into a workflow without checking it out
SQLTrackingService tracks incorrect WorkflowInstanceEvent order?
XAML Workflows, Property Bindings and Conditions sample
Tracking query timeouts

Categories

MSDN
Windows Desktop Develo...
Microsoft Office for D...
Apps for Office and Sh...
Architecture
Smart Device Development
Windows Live Developer
Orchard
Archived Forums I-L
Archived Forums M
Microsoft Partner Center
Skype for Business
Software Entwicklung f...
Visual Studio LightSwi...
Visual Studio Code Vis...
Visual Studio Tools fo...
Developing Universal W...
Application Compatibil...
Windows Desktop Optica...
Application Security f...
Windows Desktop Ribbon...
Office 365 for Developers
Developing Apps for Sh...
Azure App Service - AP...
Cognitive Services
Azure Time Series Insi...
Common Language Runtim...
Team Foundation Server...
Team Foundation Server...
Visual FoxPro General
WCF Data Services
ADO.NET DataSet
Microsoft Translator H...
Small Basic
Microsoft Robotics - D...
.NET Framework inside ...
SQL Server Notificatio...
SQL Server Compact
SQL Server Data Tools
SQL Server 2012 Setup ...
Windows Forms General
Windows Forms Designer
Windows Server 2008 Ap...
Live Connect (Archived)
MSDN and TechNet Searc...
Script Junkie Discussion
Speech Service for Dev...
WebsitePanel - Support
Open Specifications Qu...
Office Protocols
Project Server General...
Project Customization ...
Microsoft Unified Comm...
Microsoft Lync Persist...
Microsoft Unified Comm...
Game Development with ...
Silverlight Video and ...
Connected Services Fra...
Retired SharePoint Bus...
Retired SharePoint Exc...
Retired SharePoint Col...
Acropolis
App Producer (archived)
ISV Community Days
LINQ Project General
LINQ to SQL (Pre-Release)
Microsoft Security Dev...
Monitor, Alert and Aut...
Office Live Small Busi...
Search Server: Report ...
Silverlight (formerly ...
SQL Server in Azure VMs
SQL Server 2014 Data Q...
UI Design for Windows ...
Visual Basic 2008 (Pre...
Visual Basic Express E...
Visual Studio 2008 Exp...
Visual Studio Code Ana...
Visual Studio Gallery ...
Visual Studio Team Sys...
Visual Studio Team Sys...
Visual Studio Web Perf...
Windows Workflow Found...
Windows Phone Preview ...
Windows Containers
Microsoft Graph

Resources

Encrypt Message



code
soft
python
ios
c
html
jquery
cloud
mobile