Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi

I am working on statemachine in WF.Invoking workflow using WorkflowApplication.

after creating instance and calling workflow by instance.Run() method.

Then instance.unload() i am calling.When run method called respective codeActivity is getting executed where i am creating the bookmarks.

But workflow aborts unexpectingly and moving to executing status.

when i keep Thread.Sleep(new TimeSpan(0,0,5)) then it is working.

My code is like this
C#
WorkflowApplication instance = new WorkFLowApplication();// sample code only

instance.store = somestorename;
instance.complete += event;
instance.run();
Thread.Sleep(new TimeSpan(0,0,5))
instance.unload();


only by keeping Thread.Sleep(new TimeSpan(0,0,5)) its working properly. i.e. executing codeactivities with some business logic and creating bookmarks.

But i think using Thread.Sleep is not correct way of design.

Even i tried with making workflowapplication as synchronous by using SynchroniseContext.

but no success...

Please help on this
Posted
Updated 4-Jun-15 19:09pm
v2

1 solution

I would use AutoResetEvent and WaitOne to wait host application until workflow complete. sample code[^]:
C#
AutoResetEvent syncEvent = new AutoResetEvent(false);

Activity wf = new WriteLine
{
    Text = "Hello World."
};

// Create the WorkflowApplication using the desired
// workflow definition.
WorkflowApplication wfApp = new WorkflowApplication(wf);

// Handle the desired lifecycle events.
wfApp.Completed = delegate(WorkflowApplicationCompletedEventArgs e)
{
    syncEvent.Set();
};

// Start the workflow.
wfApp.Run();

// Wait for Completed to arrive and signal that
// the workflow is complete.
syncEvent.WaitOne();
 
Share this answer
 
Comments
KVPalem 5-Jun-15 3:09am    
Thanks for your update. i did followed same now. but i am getting exception as below while creating second bookmark

Type : System.Runtime.DurableInstancing.InstanceLockedException, System.Runtime.DurableInstancing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
Message : The execution of an InstancePersistenceCommand was interrupted because the instance '177ada5d-d5cb-419c-b6f1-342584f04c8f' is locked by a different instance owner. This error usually occurs because a different host has the instance loaded. The instance owner ID of the owner or host with a lock on the instance is '283b92ff-8e8a-4aba-a90b-31ef6d0e255e'.

Please help on this
KVPalem 5-Jun-15 8:47am    
Solved the problem.
romiltonfdo 8-Feb-16 2:28am    
Hi KVPalem, I got the same issue. But i can't solve that. Can you help me to solve this issues. "The execution of an InstancePersistenceCommand was interrupted because the instance '177ada5d-d5cb-419c-b6f1-342584f04c8f' is locked by a different instance owner. This error usually occurs because a different host has the instance loaded. The instance owner ID of the owner or host with a lock on the instance is '283b92ff-8e8a-4aba-a90b-31ef6d0e255e'".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900