Ejemplo n.º 1
0
        /// <summary>
        /// Executes the Activity
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(NativeActivityContext context)
        {
            //
            //  We must enter a NoPersist zone because it looks like we're idle while our
            //  Task is executing but, we aren't really
            //
            NoPersistHandle noPersistHandle = NoPersistHandle.Get(context);

            noPersistHandle.Enter(context);

            //
            //  Set a bookmark that we will resume when our Task is done
            //
            m_Bookmark = context.CreateBookmark(BookmarkResumptionCallback);
            this.Bookmark.Set(context, m_Bookmark);
            m_BookmarkResumptionHelper = context.GetExtension <BookmarkResumptionHelper>();

            //
            //  Prepare to execute
            //
            PrepareToExecute(context);

            //
            //  Start a Task to do the actual execution of our activity
            //
            CancellationTokenSource tokenSource = new CancellationTokenSource();

            m_Task = Task.Factory.StartNew(ExecuteNonblocking, tokenSource.Token);
            m_Task.ContinueWith(TaskCompletionCallback);
        }
        protected override void Execute(NativeActivityContext context)
        {
            var noPersistHandle = NoPersistHandle.Get(context);

            noPersistHandle.Enter(context);

            var bookmark = context.CreateBookmark(BookmarkResumptionCallback);

            this.Bookmark.Set(context, bookmark);

            BookmarkResumptionHelper helper = context.GetExtension <BookmarkResumptionHelper>();
            Action <IAsyncResult>    resumeBookmarkAction = (result) =>
            {
                helper.ResumeBookmark(bookmark, result);
            };

            IAsyncResult asyncResult = this.BeginExecute(context, AsyncCompletionCallback, resumeBookmarkAction);

            if (asyncResult.CompletedSynchronously)
            {
                noPersistHandle.Exit(context);
                context.RemoveBookmark(bookmark);
                EndExecute(context, asyncResult);
            }
        }
Ejemplo n.º 3
0
        private void BookmarkResumptionCallback(NativeActivityContext context, Bookmark bookmark, object value)
        {
            var noPersistHandle = NoPersistHandle.Get(context);

            if (m_Task.IsFaulted)
            {
                //
                //  The task had a problem
                //
                Console.WriteLine("Exception from ExecuteNonBlocking task:");
                Exception ex = m_Task.Exception;
                while (ex != null)
                {
                    Console.WriteLine(ex.Message);
                    ex = ex.InnerException;
                }

                //
                // If there was an exception exit the no persist handle and rethrow.
                //
                if (m_Task.Exception != null)
                {
                    noPersistHandle.Exit(context);
                    throw m_Task.Exception;
                }
            }

            AfterExecute(context);

            noPersistHandle.Exit(context);
        }
        private void BookmarkResumptionCallback(NativeActivityContext context, Bookmark bookmark, object value)
        {
            var noPersistHandle = NoPersistHandle.Get(context);

            noPersistHandle.Exit(context);
            // unnecessary since it's not multiple resume:
            // context.RemoveBookmark(bookmark);

            IAsyncResult asyncResult = value as IAsyncResult;

            this.EndExecute(context, asyncResult);
        }