Esempio n. 1
0
        /// <summary>
        /// Confirm the request
        /// </summary>
        /// <param name="tcs">Confirm task completion source</param>
        internal void ConfirmRequest(ConfirmTaskCompletionSource tcs)
        {
            if (cancellationToken.IsCancellationRequested)
            {
                tcs.SetCanceled();
            }

            lock (confirmTaskLock)
            {
                currentTaskSource = tcs;
            }

            try
            {
                bool result = ConfirmWriter(string.Empty, tcs.Message, Resources.ConfirmCaption);
                tcs.SetResult(result);
            }
            catch (Exception e)
            {
                tcs.SetException(e);
            }

            lock (confirmTaskLock)
            {
                currentTaskSource = null;
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Async confirmation.
        /// *****Please note*****
        /// Dead lock will happen if the main thread is blocked.
        /// </summary>
        /// <param name="message">Confirm message</param>
        public Task <bool> ConfirmAsync(string message)
        {
            ConfirmTaskCompletionSource tcs = new ConfirmTaskCompletionSource(message);

            ConfirmQueue.Value.Enqueue(tcs);
            return(tcs.Task);
        }
Esempio n. 3
0
 /// <summary>
 /// Process all the confirmation request
 /// </summary>
 protected void ProcessConfirmRequest()
 {
     if (ConfirmQueue.IsValueCreated)
     {
         ConfirmTaskCompletionSource tcs = null;
         while (ConfirmQueue.Value.TryDequeue(out tcs))
         {
             ConfirmRequest(tcs);
         }
     }
 }
Esempio n. 4
0
        /// <summary>
        /// Cancel the confirmation request
        /// </summary>
        public void CancelConfirmRequest()
        {
            ConfirmTaskCompletionSource tcs = null;

            while (ConfirmQueue.Value.TryDequeue(out tcs))
            {
                tcs.SetCanceled();
            }

            lock (confirmTaskLock)
            {
                if (currentTaskSource != null)
                {
                    currentTaskSource.SetCanceled();
                }

                currentTaskSource = null;
            }
        }