示例#1
0
        //--------
        public static IAsyncResult BeginInvoke <T>(/*this*/ Action <T> dlgt,
                                                   T obj, AsyncCallback callback, object @object)
        {
            AsyncResultNoResult ar    = new AsyncResultNoResult(callback, @object);
            WaitCallback        dlgt2 = delegate {
                try {
                    dlgt(obj);
                } catch (Exception ex) {
                    ar.SetAsCompleted(CreateTargetInvocationException(ex), false);
                    return;
                }
                ar.SetAsCompleted(null, false);
            };

#if THREAD_NOT_POOL && !NETCF
            var f = dlgt2.Method;
            ParameterizedThreadStart dlgt2TP = (ParameterizedThreadStart)
                                               Delegate.CreateDelegate(typeof(ParameterizedThreadStart), dlgt2.Target, f, true);
            //ThreadStart dlgt2T = (ThreadStart)
            //    Delegate.CreateDelegate(typeof(ThreadStart), dlgt2.Target, f, true);
            var t = new Thread(dlgt2TP);
            t.IsBackground = true;
            t.Start();
#else
            ThreadPool.QueueUserWorkItem(dlgt2);
#endif
            return(ar);
        }
示例#2
0
        /// <summary>
        /// Helper for asynchronously removing a folder.
        /// </summary>
        /// <param name="asyncResult">AsyncResultNoResult&lt;Folder&gt;</param>
        private void RemoveFolderAsyncHelper(object asyncResult)
        {
            AsyncResultNoResult <Folder> ar = (AsyncResultNoResult <Folder>)asyncResult;

            try {
                RemoveFolder(ar.Parameter1);
                ar.SetAsCompleted(null, false);
            }
            catch (Exception e) {
                ar.SetAsCompleted(e, false);
            }
        }
示例#3
0
        /// <summary>
        /// Helper method to asynchronously save documents
        /// </summary>
        /// <param name="asyncResult">AsyncResultNoResult&lt;Document&gt;</param>
        private void SaveDocumentAsyncHelper(object asyncResult)
        {
            AsyncResultNoResult <Document> ar = (AsyncResultNoResult <Document>)asyncResult;

            try {
                SaveDocument(ar.Parameter1);
                ar.SetAsCompleted(null, false);
            }
            catch (Exception e) {
                ar.SetAsCompleted(e, false);
            }
        }
示例#4
0
        /// <summary>
        /// Helper facilitating asynchronous sharing of projects
        /// </summary>
        /// <param name="asyncResult">AsyncResultNoResult&lt;Project, IEnumerable&lt;string&gt;&gt;</param>
        private void ShareProjectAsyncHelper(object asyncResult)
        {
            AsyncResultNoResult <Project, IEnumerable <string> > ar = (AsyncResultNoResult <Project, IEnumerable <string> >)asyncResult;

            try {
                ShareProject(ar.Parameter1, ar.Parameter2);
                ar.SetAsCompleted(null, false);
            }
            catch (Exception e) {
                ar.SetAsCompleted(e, false);
            }
        }
示例#5
0
        private void DoConnect(object asyncResult)
        {
            AsyncResultNoResult result = asyncResult as AsyncResultNoResult;

            try
            {
                this.Connect();
                result.SetAsCompleted(null, false);
            }
            catch (Exception exception)
            {
                result.SetAsCompleted(exception, false);
            }
        }
        public override IAsyncResult BeginConnect(BluetoothEndPoint remoteEP, AsyncCallback requestCallback, object state)
        {
            var ar = new AsyncResultNoResult(requestCallback, state);

            System.Threading.ThreadPool.QueueUserWorkItem(_ =>
            {
                try {
                    Connect(remoteEP);
                    ar.SetAsCompleted(null, AsyncResultCompletion.IsAsync);
                } catch (Exception ex) {
                    ar.SetAsCompleted(ex, AsyncResultCompletion.IsAsync);
                }
            });
            return(ar);
        }
示例#7
0
        public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state)
        {
            var result = new AsyncResultNoResult(callback, state);

            result.SetAsCompleted(null, true);
            return(result);
        }
示例#8
0
        public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
        {
            this.LockHeaders();
            var asyncResult = new AsyncResultNoResult(callback, state);

            asyncResult.SetAsCompleted(null, true);
            return(asyncResult);
        }
示例#9
0
        private void OnBeginPushMessageToClients(object asyncResult)
        {
            AsyncResultNoResult ar = asyncResult as AsyncResultNoResult;

            try {
                // Perform the operation; if sucessful set the result
                PushData pushData = ar.AsyncState as PushData;
                //Restore context
                FluorineWebSafeCallContext.SetData(FluorineContext.FluorineContextKey, pushData.Context);
                PushMessageToClients(pushData.Subscribers, pushData.Message);
                ar.SetAsCompleted(null, false);
            } catch (Exception ex) {
                // If operation fails, set the exception
                ar.SetAsCompleted(ex, false);
            } finally {
                FluorineWebSafeCallContext.FreeNamedDataSlot(FluorineContext.FluorineContextKey);
            }
        }
示例#10
0
        private void OnBeginInvokeClients(object asyncResult)
        {
            AsyncResultNoResult ar = asyncResult as AsyncResultNoResult;

            try {
                // Perform the operation; if sucessful set the result
                InvokeData invokeData = ar.AsyncState as InvokeData;
                //Restore context
                FluorineWebSafeCallContext.SetData(FluorineContext.FluorineContextKey, invokeData.Context);
                InvokeClients(invokeData.Method, invokeData.Arguments, invokeData.Callback, invokeData.IgnoreSelf, invokeData.TargetScope);
                ar.SetAsCompleted(null, false);
            } catch (Exception ex) {
                // If operation fails, set the exception
                ar.SetAsCompleted(ex, false);
            } finally {
                FluorineWebSafeCallContext.FreeNamedDataSlot(FluorineContext.FluorineContextKey);
            }
        }
示例#11
0
        private void DoConnect(object asyncResult)
        {
            AsyncResultNoResult ar = asyncResult as AsyncResultNoResult;

            try {
                // Perform the operation; if sucessful set the result
                Connect();
                if (ar != null)
                {
                    ar.SetAsCompleted(null, false);
                }
            } catch (Exception ex) {
                // If operation fails, set the exception
                if (ar != null)
                {
                    ar.SetAsCompleted(ex, false);
                }
            }
        }
示例#12
0
 public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state)
 {
     var result = new AsyncResultNoResult(callback, state);
     result.SetAsCompleted(null, true);
     return result;
 }
 public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
 {
     this.LockHeaders();
     var asyncResult = new AsyncResultNoResult(callback, state);
     asyncResult.SetAsCompleted(null, true);
     return asyncResult;
 }