| Subject: Windows Workflow foundation - troubles with multithreading |
| Group: microsoft.public.windows.developer.winfx.general |
| Date: 8/6/2007 2:00:00 AM |
| From: =?Utf-8?B?b3Bwb3Nlcg==?= [Email Address Protection] |
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) |
| Back |
| Subject: Re: Windows Workflow foundation - troubles with multithreading |
| Group: microsoft.public.windows.developer.winfx.general |
| Date: 9/18/2007 3:27:41 AM |
| From: "Thorsten Tarrach [MSFT]" [Email Address Protection] |
Hi, probably to late for your deadline, but have you tried the ManualWorkflowSchedulerService? It delays running the workflow until you call the ManualWorkflowSchedulerService.RunWorkflow Method. This method runs the workflow in the current thread and returns once the workflow is back in idle state. This should solve your multithreading problems if it is acceptable that the GUI thread is blocked while the workflow is running. Thorsten -- This posting is provided "AS IS" with no warranties, and confers no rights. "opposer" <opposer@discussions.microsoft.com> wrote in message news:3A076AA5-CA29-4661-980B-C23A57D9A779@microsoft.com... > 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) |
| Back |