View Single Post
Old 08-06-2007   #1 (permalink)
opposer
Guest


 

Windows Workflow foundation - troubles with multithreading

I'm developing app kinda like Diagnosis Tree - it asks question by question
in question tree and user replies. Using WF. Doing like this:

Engine creates and starts sequental workflow filled with ListenActivity and
CallExternalMethod activities. CallExternalMethod calls method in
GuiController object(interfaces and stuff are correct) passing question text.
GuiController changes form1.Label1.Text to question text. Then user presses
Yes or No, and Engine is subscribed to these events and it fires YesPressed
and NoPressed events, which ListenActivity activities are listening. And
workflow goes on.

Problem is like this: to modify form1 content i have to switch threads to
thread which created this form.
Doing it like this:

if (!form1.InvokeRequired)
{
form1.label2.Text = question;
}
else
{
ModifyFormDelegate del = new ModifyFormDelegate(ChangeValue);
form1.Invoke(del, new object[] { question }).ToString();
}

Question text appears. Then user presses Yes, and exception appears

Event "RepliedYesEvent" on interface type
"TreesEngine.IYesNoExchangeService" for instance id
"3b8bad4c-de1b-4648-845e-2214d6204614" cannot be delivered.

Inner Detail:
{"The workflow hosting environment does not have a persistence service as
required by an operation on the workflow instance
\"bf69fa59-8689-4b87-80b4-602a0579883e\"."}

I created Persistence database(scripts from Framework 3.0 installation) and
added Persistance service.

System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService
sqlPersistenceService = new
System.Workflow.Runtime.Hosting.SqlWorkflowPersistenceService("Initial
Catalog=SqlPersistenceService;Data Source=localhost;Integrated
Security=SSPI", true, new TimeSpan(0, 0, 0, 10, 0), new TimeSpan(0, 0, 0, 10,
0));
workflowRuntime.AddService(sqlPersistenceService);

and InnerException looks like
{"Workflow with id \"1ae438c6-ea0b-4a44-812d-a6930b093821\" not found in
state persistence store."}.

If i don't switch threads, everything is fine, but i can't modify form
elements.
Are there any solutions? Help me please, deadline is getting too close.

Perhaps any other ways to implement pattern like this? (workflow-driven Gui
execution)