Exemplo n.º 1
0
        public async Task Enqueue_Action_Runs_On_Current_Thread()
        {
            var thread = default(Thread);
            await _NullDispatcher.Enqueue(() => { thread = Thread.CurrentThread; });

            thread.Should().Be(Thread.CurrentThread);
        }
Exemplo n.º 2
0
        public async Task Stress()
        {
            ParameterizedThreadStart safeAction = ctx =>
            {
                var completion = ctx as TaskCompletionSource <int>;
                _Dispatcher.Enqueue(() =>
                {
                    Thread.Sleep(2);
                    Count++;
                }).ContinueWith(_ => completion?.TrySetResult(0));
            };

            await PrivateStress(safeAction);
        }
Exemplo n.º 3
0
 private void RaiseUploadStatusCallback(Action <UploadStatusMessage> uploadStatusCallback, long contentLength, long contentUploadedThisRound, long totalContentUploaded)
 {
     if (uploadStatusCallback != null)
     {
         _dispatcher.Enqueue(() =>
         {
             uploadStatusCallback(new UploadStatusMessage()
             {
                 ContentLength            = contentLength,
                 ContentUploadedThisRound = contentUploadedThisRound,
                 TotalContentUploaded     = totalContentUploaded
             });
         });
     }
 }
Exemplo n.º 4
0
        public async Task Stress()
        {
            void SafeAction(object ctx)
            {
                var completion = ctx as TaskCompletionSource <int>;

                _Dispatcher.Enqueue(() =>
                {
                    Thread.Sleep(2);
                    Count++;
                })
                .ContinueWith(_ => completion?.TrySetResult(0));
            }

            await PrivateStress(SafeAction);
        }
Exemplo n.º 5
0
 private void RaiseErrorResponse(Action <HttpResponseMessage> action, Exception exception)
 {
     if (action != null)
     {
         _dispatcher.Enqueue(() =>
         {
             action(new HttpResponseMessage()
             {
                 Exception = exception,
             });
         });
     }
 }
Exemplo n.º 6
0
        private static void PutObjectCallback(IAsyncResult ar)
        {
            Hashtable       state       = (Hashtable)ar.AsyncState;
            Action <string> putCallback = (Action <string>)state["callback"];

            try
            {
                OssClient  ossClient   = (OssClient)state["client"];
                FileStream fs          = (FileStream)state["fs"];
                string     ossfilename = (string)state["ossfilename"];
                ossClient.EndPutObject(ar);
                fs.Close();
                _dispatcher.Enqueue(() => {
                    if (putCallback != null)
                    {
                        putCallback(ossfilename);
                    }
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                _dispatcher.Enqueue(() => {
                    if (putCallback != null)
                    {
                        if (ex is ServiceException)
                        {
                            string errorCode = ((ServiceException)ex).ErrorCode;
                            putCallback(errorCode);
                            if (errorCode == "InvalidAccessKeyId")
                            {
                                FetchSTSToken();
                            }
                        }
                        else
                        {
                            putCallback(ex.Message);
                        }
                    }
                });
            }
            finally
            {
//				_event.Set();
            }
        }