MadVax

Hello,

I have a WebService and call that:

public void Execute()

{

...

try

{

this.workflowInstance = this.workflowRuntime.CreateWorkflow(typeof(Workflows.wf_ReglesSite), this.namedArgumentValues);

UpdateRules(this.workflowInstance, this.RulesFile);

}

...

}

The UpdateRules fonction is like that:

private void UpdateRules(WorkflowInstance instance, string fileRules)

{

XmlTextReader reader = new XmlTextReader(fileRules);

WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();

RuleDefinitions rules = serializer.Deserialize(reader) as RuleDefinitions;

WorkflowChanges changes = new WorkflowChanges(instance.GetWorkflowDefinition()); ***

changes.TransientWorkflow.SetValue(RuleDefinitions.RuleDefinitionsProperty, rules);

instance.ApplyWorkflowChanges(changes);

reader.Close();

}

When I call the WebService for the first time, all is , but the second call is not so good , the WorkFlowRuntime is disposed.

The line with *** return this error:

System.ObjectDisposedException: Impossible d'accéder à un objet supprimé.
Nom de l'objet : 'WorkflowRuntime'.
a System.Workflow.Runtime.WorkflowRuntime.GetService[T]()
a System.Workflow.Runtime.WorkflowDefinitionDispenser.LoadRootActivity(Type workflowType, Boolean createDefinition, Boolean initForRuntime)
a System.Workflow.Runtime.WorkflowDefinitionDispenser.GetRootActivity(Type workflowType, Boolean createNew, Boolean initForRuntime)
a System.Workflow.Runtime.WorkflowRuntime.OnActivityDefinitionResolve(Object sender, ActivityResolveEventArgs e)
a System.Workflow.ComponentModel.Activity.OnResolveActivityDefinition(Type type, String workflowMarkup, String rulesMarkup, Boolean createNew, Boolean initForRuntime)
a System.Workflow.ComponentModel.WorkflowChanges.CloneRootActivity(Activity originalRootActivity)
a System.Workflow.ComponentModel.WorkflowChanges..ctor(Activity rootActivity)

Someone have an idea

Thanks




Re: Windows Workflow Foundation Multiple Updates of Rules with WorkflowChanges

Kavita Kamani - MSFT

The typical pattern is to make dynamic updates when your WF is idle and hook to the OnWorkflowIdle event, get the WF instance from the event args and then make changes on that instance. Do you really want to create a new instance each time in your execute method and then use dynamic updates to change the rule definitions on that instance




Re: Windows Workflow Foundation Multiple Updates of Rules with WorkflowChanges

MadVax

Yes, I want to use dynamic updates to change the rule definitions from a .rules file (with just one RuleSet) because Workflows.wf_ReglesSite have the same defintion but the RuleSet is empty. The .rules file can be modified and we need the last version of this.

I give you the complete Execute() method:

public void Execute()

{

using (this.workflowRuntime = new WorkflowRuntime())

{

AutoResetEvent waitHandle = new AutoResetEvent(false);

this.workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) { waitHandle.Set(); };

this.workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e) { waitHandle.Set(); };

try

{

this.workflowInstance = this.workflowRuntime.CreateWorkflow(typeof(Workflows.wf_ReglesSite), this.namedArgumentValues);

UpdateRules(this.RulesFile);

}

catch (...) {...}

this.workflowInstance.Start();

waitHandle.WaitOne();






Re: Windows Workflow Foundation Multiple Updates of Rules with WorkflowChanges

Kavita Kamani - MSFT

Could you send me your project and I can take a look. My email is kavitak at microsoft dot com.

However, if you'd like an opinion on this design, it is not obvious that using WorkflowChanges is the right approach here. As I said, dynamic updates are used when your WF becomes idle and then you want to modify the activity tree or modify rules. You are trying to modify using WorkflowChanges before starting the instance. A possibly better way of doing this is to use the CreateWorkflow overload that takes a reader to your rules






Re: Windows Workflow Foundation Multiple Updates of Rules with WorkflowChanges

Constantin Mihai - MSFT

Hi,

This looks more like a contention issue on your service's workflowRuntime instance property/field. I can see that you re-instantiate it each time you call the Execute method. So, you might want to make it a local (Execute method) variable OR cache its value on a per service instance basis and lock the access to it everywhere you use it.

I suspect that a third call to the Execute method is coming to soon and determines a disposal of the workflowRuntime value currently in use (created through your second call).

Let me know if any of the suggestions above works for you. If not, please provide an isolated scenario of Execute method calls that reproduces the issue.

Thanks!





Re: Windows Workflow Foundation Multiple Updates of Rules with WorkflowChanges

Kavita Kamani - MSFT

Did you try this I also replied to your email with some suggestions yesterday.




Re: Windows Workflow Foundation Multiple Updates of Rules with WorkflowChanges

MadVax

Thanks for your replies, I didn't try your suggestions yet.

but I may have time next week. I just try to use the CreateWorkflow overload that takes a reader but I have some code in my sequential workflow and the first parameter is the workflowDefinition ( xoml file ) which not contain it.

I just want to have an external file .rules (containing a RuleSet) and replace the existing RuleSet in my PolicyActivity.






Re: Windows Workflow Foundation Multiple Updates of Rules with WorkflowChanges

Constantin Mihai - MSFT

Hi,

Feel free to open a new thread for this separate issue.

Thanks!





Re: Windows Workflow Foundation Multiple Updates of Rules with WorkflowChanges

Jurgen Willis

MadVax wrote:

I just want to have an external file .rules (containing a RuleSet) and replace the existing RuleSet in my PolicyActivity.

You might want to look at the External Ruleset Demo sample available on our community site:

http://wf.netfx3.com/files/folders/rules_samples/entry309.aspx






Re: Windows Workflow Foundation Multiple Updates of Rules with WorkflowChanges

MadVax

I look the sample on your community site and it's exactly what I want !!!

Thanks for your help