コード例 #1
0
 public static void RunSynchronously(Task task)
 {
     while (!task.IsCompleted)
     {
         if (!ForegroundSynchronizationContext.ProcessAsyncTasks())
         {
             System.Threading.Thread.Sleep(50);
         }
     }
     task.GetAwaiter().GetResult();
 }
コード例 #2
0
ファイル: MessagePuller.cs プロジェクト: octogonz/yamster
        /// <summary>
        /// Performs one step of the sync algorithm, which makes at most one service call
        /// to the Yammer REST endpoint.  This method is intended to be called at periodic intervals
        /// and may return without doing any work, e.g. if the state machine is waiting for a timeout.
        /// </summary>
        public void Process()
        {
            ForegroundSynchronizationContext.ProcessAsyncTasks();

            // Avoid reentrancy that could occur e.g. if the CallingService event handler calls
            // Utilities.ProcessApplicationEvents(), which causes another timer event to be processed.
            if (alreadyProcessing)
            {
                return;
            }
            try
            {
                alreadyProcessing = true;

                // Make sure the previous async task has completed
                if (previousAsyncTask != null)
                {
                    bool finished = previousAsyncTask.IsCanceled || previousAsyncTask.IsCompleted ||
                                    previousAsyncTask.IsFaulted;

                    if (previousAsyncTask.IsFaulted)
                    {
                        var innerException = previousAsyncTask.Exception.InnerExceptions.First();
                        throw new Exception("A problem occurred while syncing messages.",
                                            innerException);
                    }
                    if (!finished)
                    {
                        return;
                    }
                }

                previousAsyncTask = ProcessAsync();
            }
            finally
            {
                alreadyProcessing = false;
            }

            ForegroundSynchronizationContext.ProcessAsyncTasks();
        }
コード例 #3
0
        public void DeleteFromServer()
        {
            var task = DeleteFromServerAsync();

            ForegroundSynchronizationContext.RunSynchronously(task);
        }