locked
SynchronizationContext and Bookmarks in WF4 RRS feed

  • General discussion

  • I am running workflows under asp.net and using SynchronizationContext to make the page "wait" for the workflow. Here is how I run the workflow instance under asp.net:

    var workflowApplication = new WorkflowApplication(activity); 
    SynchronizationContext syncContext = SynchronizationContext.Current; 
    workflowApplication.Completed = delegate { syncContext.OperationCompleted(); }; 
    workflowApplication.SynchronizationContext = syncContext; 
    syncContext.OperationStarted(); 
    workflowApplication.Run(); 


    In one of the activities I use a bookmark. Now I want the page processing to continue whenever I call CreateBookmark. I tried calling SynchronizationContext.Current.OperationCompleted() before setting the bookmark but that crushes asp.net site when the workflow resumes and completes (I think the workflow instance calls OperationCompleted again when it completes and the error raises)

    How can I work with bookmarks under Asp.Net, any ideas?

    • Changed type Andrew_Zhu Friday, May 28, 2010 7:18 AM no follow up
    Saturday, May 22, 2010 1:58 PM

All replies

  • don't use SynchronizationContext like that, you can write your own SynchronizationContext class as this:

    class SynchronousSynchronizationContext : SynchronizationContext { private static SynchronousSynchronizationContext value; public override void Post(SendOrPostCallback d, object state) { d(state); } public override void Send(SendOrPostCallback d, object state) { d(state); } public static SynchronousSynchronizationContext Value { get { if (value == null) { value = new SynchronousSynchronizationContext(); } return value; } } }

    //

     workflowApplication .SynchronizationContext = SynchronousSynchronizationContext.Value;

    // I found this by reflect the Framework code, and it work well.

    Sunday, May 23, 2010 12:56 PM
  • the code :

    class SynchronousSynchronizationContext : SynchronizationContext
      {
        private static SynchronousSynchronizationContext value;
        public override void Post(SendOrPostCallback d, object state)
        {
          d(state);
        }
    
        public override void Send(SendOrPostCallback d, object state)
        {
          d(state);
        }
    
        public static SynchronousSynchronizationContext Value
        {
          get
          {
            if (value == null)
            {
              value = new SynchronousSynchronizationContext();
            }
            return value;
          }
        }
      }
    
    //
    
     workflowApplication .SynchronizationContext = SynchronousSynchronizationContext.Value;

    Sunday, May 23, 2010 12:59 PM
  • In one of the activities I use a bookmark. Now I want the page processing to continue whenever I call CreateBookmark. I tried calling SynchronizationContext.Current.OperationCompleted() before setting the bookmark but that crushes asp.net site when the workflow resumes and completes (I think the workflow instance calls OperationCompleted again when it completes and the error raises)

    How can I work with bookmarks under Asp.Net, any ideas?


    In your example, do you want the workflow to execute up until it creates the bookmark and goes idle, and then you want the page processing to continue? And then later on you want to resume the bookmark (from another page?) You could make the call the OperationCompleted from the Idle handler or PersistableIdle handler (if you are using persistence, I don't see it configured in your example but you are probably just giving an abbreviated sample code)

    Steve Danielson [Microsoft]
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Use of included script samples are subject to the terms specified at http://www.microsoft.com/info/cpyright.htm

     

     

    Monday, May 24, 2010 3:06 PM
  • Hi, Sylvie

    We are changing the issue type to "General Discussion" because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to Question. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

    Thank you!


    This posting is provided "AS IS" with no warranties, and confers no rights. Microsoft Online Community Support
    Friday, May 28, 2010 7:18 AM