private void OnTimerFired(object state)
        {
            Bookmark timerBookmark = state as Bookmark;

            WorkflowInstanceProxy targetInstance = this.instance;

            // it's possible that we've been unloaded while the timer was in the process of firing, in
            // which case targetInstance will be null
            if (targetInstance != null)
            {
                BookmarkResumptionResult resumptionResult;
                IAsyncResult             result = null;
                bool completed = false;

                result = targetInstance.BeginResumeBookmark(timerBookmark, null, TimeSpan.MaxValue,
                                                            onResumeBookmarkComplete, new BookmarkResumptionState(timerBookmark, this, targetInstance));
                completed = result.CompletedSynchronously;

                if (completed && result != null)
                {
                    try
                    {
                        resumptionResult = targetInstance.EndResumeBookmark(result);
                        ProcessBookmarkResumptionResult(timerBookmark, resumptionResult);
                    }
                    catch (TimeoutException)
                    {
                        ProcessBookmarkResumptionResult(timerBookmark, BookmarkResumptionResult.NotReady);
                    }
                }
            }
        }
 static void OnResumeBookmarkCompleted(IAsyncResult result)
 {
     if (!result.CompletedSynchronously)
     {
         WorkflowInstanceProxy instance = result.AsyncState as WorkflowInstanceProxy;
         Fx.Assert(instance != null, "BeginResumeBookmark should pass a WorkflowInstanceProxy object as the async state object.");
         instance.EndResumeBookmark(result);
     }
 }
Exemple #3
0
 internal void OnWaiterFired(object sender, WaiterEventArgs args)
 {
     // Waiter was fired, resume the bookmark
     _instance.BeginResumeBookmark(
         _bookmark,
         args.Message,
         (asr) => _instance.EndResumeBookmark(asr),
         null);
 }
        /// <summary>
        /// Used to resume bookmark outside workflow.
        /// </summary>
        /// <param name="bookmark">The value of Bookmark to be resumed</param>
        public void ResumeBookmark(Bookmark bookmark)
        {
            IAsyncResult asyncResult = _instance.BeginResumeBookmark(bookmark, null, Fx.ThunkCallback(new AsyncCallback(StateMachineExtension.OnResumeBookmarkCompleted)), _instance);

            if (asyncResult.CompletedSynchronously)
            {
                _instance.EndResumeBookmark(asyncResult);
            }
        }
Exemple #5
0
        public void WaitSome(Bookmark bookmark)
        {
            ThreadPool.QueueUserWorkItem(state =>
            {
                Thread.Sleep(1000);
                var ias = _instance.BeginResumeBookmark(bookmark, 42, null, null);

                var result = _instance.EndResumeBookmark(ias);

                if (System.Diagnostics.Debugger.IsAttached)
                {
                    System.Diagnostics.Debug.WriteLine("BookmarkResumptionResult: '{0}'", result);
                }
            });
        }
        private void OnTimerFired(object state)
        {
            Bookmark nextExpiredBookmark;

            lock (this.ThisLock)
            {
                nextExpiredBookmark = this.RegisteredTimers.GetNextExpiredBookmark();
                if ((nextExpiredBookmark == null) || (this.RegisteredTimers.GetNextDueTime() > DateTime.UtcNow))
                {
                    return;
                }
            }
            WorkflowInstanceProxy instance = this.instance;

            if (instance != null)
            {
                IAsyncResult result2 = null;
                bool         completedSynchronously = false;
                try
                {
                    result2 = instance.BeginResumeBookmark(nextExpiredBookmark, null, TimeSpan.FromSeconds(2.0), onResumeBookmarkComplete, new BookmarkResumptionState(nextExpiredBookmark, this, instance));
                    completedSynchronously = result2.CompletedSynchronously;
                }
                catch (TimeoutException)
                {
                    this.ProcessBookmarkResumptionResult(nextExpiredBookmark, BookmarkResumptionResult.NotReady);
                }
                if (completedSynchronously && (result2 != null))
                {
                    try
                    {
                        BookmarkResumptionResult result = instance.EndResumeBookmark(result2);
                        this.ProcessBookmarkResumptionResult(nextExpiredBookmark, result);
                    }
                    catch (TimeoutException)
                    {
                        this.ProcessBookmarkResumptionResult(nextExpiredBookmark, BookmarkResumptionResult.NotReady);
                    }
                }
            }
        }
Exemple #7
0
 internal void ResumeBookmark(Bookmark bookmark, object value)
 {
     _instance.EndResumeBookmark(
         _instance.BeginResumeBookmark(bookmark, value, null, null));
 }
 internal BookmarkResumptionResult ResumeBookmark(Bookmark bookmark, object value)
 {
     return(_workflowInstance.EndResumeBookmark(_workflowInstance.BeginResumeBookmark(bookmark, value, null, null)));
 }