locked
editing WorkFlowElement after running it RRS feed

  • Question

  • Hi!

    I have an app, where I rehost the WF4 designer. I want let the user the create workflows, run them and modify them after running. But after running a WF If you try to edit it ie. insert a new activity or delete one from a sequence, u get the following exception:

    "WorkflowElement 'Sequence' cannot be modified because it has been locked. A WorkflowElement is locked when Invoke is called on the WorkflowElement, or when a WorkflowInstance is created from it using the Create method."

    however this is after the running, and I delete the WorkflowInstance as well. How could I unlock me WorkflowElement (it is a sequence)?
    Thursday, September 10, 2009 5:30 PM

Answers

  • it is working this way:

    string csq = designer.Text;
    WorkflowInstance wi = new WorkflowInstance(sq);
    wi.OnCompleted = delegate(WorkflowCompletedEventArgs ee) { syncEvent.Set(); };
    wi.OnUnhandledException = delegate(WorkflowUnhandledExceptionEventArgs ee) {
    MessageBox.Show(ee.UnhandledException.Message); return UnhandledExceptionAction.Terminate; };
    wi.Run();
    syncEvent.WaitOne();
    wi = null;
    designer.Text = csq;
    designer.Load();
    Saturday, September 12, 2009 12:04 AM

All replies

  • You have to make a clone of your WorkflowElement before running it if you want to allow changes (to that clone).
    • Marked as answer by Kenny Wolf [MSFT] Friday, September 11, 2009 12:00 AM
    • Unmarked as answer by ladeak Friday, September 11, 2009 5:42 PM
    • Marked as answer by ladeak Friday, September 11, 2009 10:39 PM
    • Unmarked as answer by ladeak Saturday, September 12, 2009 12:00 AM
    • Marked as answer by ladeak Saturday, September 12, 2009 12:06 AM
    • Unmarked as answer by ladeak Wednesday, September 16, 2009 5:03 AM
    Friday, September 11, 2009 12:00 AM
  • So if I have a Sequence which contains an If activity in that another activity etc. then I have to clone all the activities. Is there a nice (easy) way of doing this, or I have to write a totally general cloning method by using Reflections?
    (I mean, how else could I clone the built in Activities and their children?)

    • Marked as answer by ladeak Saturday, September 12, 2009 12:06 AM
    • Unmarked as answer by ladeak Wednesday, September 16, 2009 5:03 AM
    Friday, September 11, 2009 5:42 PM
  • through the designer the workflow can be get as a xaml and then can be set again.
    • Marked as answer by ladeak Friday, September 11, 2009 10:39 PM
    • Unmarked as answer by ladeak Saturday, September 12, 2009 12:00 AM
    Friday, September 11, 2009 10:39 PM
  • it is working this way:

    string csq = designer.Text;
    WorkflowInstance wi = new WorkflowInstance(sq);
    wi.OnCompleted = delegate(WorkflowCompletedEventArgs ee) { syncEvent.Set(); };
    wi.OnUnhandledException = delegate(WorkflowUnhandledExceptionEventArgs ee) {
    MessageBox.Show(ee.UnhandledException.Message); return UnhandledExceptionAction.Terminate; };
    wi.Run();
    syncEvent.WaitOne();
    wi = null;
    designer.Text = csq;
    designer.Load();
    Saturday, September 12, 2009 12:04 AM
  • true, this way you can add and delete new activities, but cannot modify old ones.
    Wednesday, September 16, 2009 5:03 AM