예제 #1
0
        //private void DownloadBlobWorker(MyAsyncContext asyncContext, out bool cancelled, AsyncOperation async)
        //{
        //    cancelled = false;

        //    ParallelDownloadFile(asyncContext, async);

        //    // check for Cancelling
        //    if (asyncContext.IsCancelling)
        //    {
        //        cancelled = true;
        //    }

        //}

        private void TaskCompletedCallback(IAsyncResult ar)
        {
            // get the original worker delegate and the AsyncOperation instance
            BlobTransferWorkerDelegate worker = (BlobTransferWorkerDelegate)((AsyncResult)ar).AsyncDelegate;
            AsyncOperation             async  = (AsyncOperation)ar.AsyncState;

            bool cancelled;

            // finish the asynchronous operation
            worker.EndInvoke(out cancelled, ar);

            // clear the running task flag
            lock (_sync)
            {
                TaskIsRunning = false;
                TaskContext   = null;
            }

            // raise the completed event
            var    asyncOperation = ar.AsyncState as AsyncOperation;
            object userState      = null;

            if (asyncOperation != null)
            {
                userState = asyncOperation.UserSuppliedState;
            }
            AsyncCompletedEventArgs completedArgs = new AsyncCompletedEventArgs(null, cancelled, userState);

            async.PostOperationCompleted(delegate(object e) { OnTaskCompleted((AsyncCompletedEventArgs)e); }, completedArgs);
        }
예제 #2
0
        public void UploadBlobAsync(CloudBlockBlob blob, string localFile, object state)
        {
            TransferType = TransferTypeEnum.Upload;
            //attempt to open the file first so that we throw an exception before getting into the async work
            using (FileStream fs = new FileStream(localFile, FileMode.Open, FileAccess.Read)) { }

            m_Blob     = blob;
            m_FileName = localFile;

            BlobTransferWorkerDelegate worker = new BlobTransferWorkerDelegate(UploadBlobWorker);
            AsyncCallback completedCallback   = new AsyncCallback(TaskCompletedCallback);

            lock (_sync)
            {
                if (TaskIsRunning)
                {
                    throw new InvalidOperationException("The control is currently busy.");
                }

                AsyncOperation async   = AsyncOperationManager.CreateOperation(state);
                MyAsyncContext context = new MyAsyncContext();

                bool cancelled;

                worker.BeginInvoke(context, out cancelled, async, completedCallback, async);

                TaskIsRunning = true;
                TaskContext   = context;
            }
        }
예제 #3
0
        public void UploadBlobAsync(CloudBlockBlob blob, string localFile, object state)
        {
            TransferType = TransferTypeEnum.Upload;
            //attempt to open the file first so that we throw an exception before getting into the async work
            using (FileStream fs = new FileStream(localFile, FileMode.Open, FileAccess.Read)) { }

            m_Blob = blob;
            m_FileName = localFile;

            BlobTransferWorkerDelegate worker = new BlobTransferWorkerDelegate(UploadBlobWorker);
            AsyncCallback completedCallback = new AsyncCallback(TaskCompletedCallback);

            lock (_sync)
            {
                if (TaskIsRunning)
                    throw new InvalidOperationException("The control is currently busy.");

                AsyncOperation async = AsyncOperationManager.CreateOperation(state);
                MyAsyncContext context = new MyAsyncContext();

                bool cancelled;

                worker.BeginInvoke(context, out cancelled, async, completedCallback, async);

                TaskIsRunning = true;
                TaskContext = context;
            }
        }