示例#1
0
        /// <summary>
        /// Ends a pending asynchronous message push.
        /// </summary>
        /// <param name="asyncResult">An IAsyncResult that stores state information and any user defined data for this asynchronous operation.</param>
        /// <remarks>
        /// <para>
        /// EndInvoke is a blocking method that completes the asynchronous message push request started in the BeginPushMessageToClients method.
        /// </para>
        /// <para>
        /// Before calling BeginPushMessageToClients, you can create a callback method that implements the AsyncCallback delegate. This callback method executes in a separate thread and is called by the system after BeginPushMessageToClients returns.
        /// The callback method must accept the IAsyncResult returned by the BeginPushMessageToClients method as a parameter.
        /// </para>
        /// <para>Within the callback method you can call the EndPushMessageToClients method to successfully complete the invocation attempt.</para>
        /// <para>The BeginPushMessageToClients enables to use the fire and forget pattern too (by not implementing an AsyncCallback delegate), however if the invocation fails the EndPushMessageToClients method is responsible to throw an appropriate exception.
        /// Implementing the callback and calling EndPushMessageToClients also allows early garbage collection of the internal objects used in the asynchronous call.</para>
        /// </remarks>
        public void EndPushMessageToClients(IAsyncResult asyncResult)
        {
            AsyncResultNoResult ar = asyncResult as AsyncResultNoResult;

            // Wait for operation to complete, then return result or throw exception
            ar.EndInvoke();
        }
示例#2
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);
        }
示例#3
0
        public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state)
        {
            var result = new AsyncResultNoResult(callback, state);

            result.SetAsCompleted(null, true);
            return(result);
        }
示例#4
0
        public void EndConnect(IAsyncResult asyncResult)
        {
            AsyncResultNoResult ar2 = (AsyncResultNoResult)asyncResult;

            ar2.EndInvoke();
            Debug.Assert(m_arConnect == null, "NOT m_arConnect == null");
        }
示例#5
0
        /// <summary>
        /// Start removing a folder asynchronously in accordance to the Asynchronous Programming Model.
        /// </summary>
        /// <param name="f">Folder to remove</param>
        /// <param name="callback">Callback called when folder has been removed</param>
        /// <param name="state">State object (passed to callback)</param>
        /// <returns>IAsyncResult for EndRemoveFolder</returns>
        /// <seealso cref="EndRemoveFolder"/>
        public IAsyncResult BeginRemoveFolder(Folder f, AsyncCallback callback, object state)
        {
            AsyncResultNoResult <Folder> ar = new AsyncResultNoResult <Folder>(callback, state, f);

            ThreadPool.QueueUserWorkItem(RemoveFolderAsyncHelper, ar);

            return(ar);
        }
示例#6
0
        /// <summary>
        /// Start removing a document asynchronously in accordance with the Asynchronous Programming Model.
        /// </summary>
        /// <param name="d">Document to remove</param>
        /// <param name="callback">Callback called on removal completion</param>
        /// <param name="state">State object (passed to callback)</param>
        /// <returns>IAsyncResult for EndRemoveDocument</returns>
        /// <seealso cref="EndRemoveDocument"/>
        public IAsyncResult BeginRemoveDocument(Document d, AsyncCallback callback, object state)
        {
            AsyncResultNoResult <Document> ar = new AsyncResultNoResult <Document>(callback, state, d);

            ThreadPool.QueueUserWorkItem(RemoveDocumentAsyncHelper, ar);

            return(ar);
        }
示例#7
0
        /// <summary>
        /// Starts sharing a project using APM.
        /// </summary>
        /// <param name="p">Project to share</param>
        /// <param name="emails">Emails to share the project with</param>
        /// <param name="callback">Callback called upon conclusion of sharing</param>
        /// <param name="stateObject">state object woopdashoopfloop</param>
        /// <returns>IAsyncResult for EnShareProject</returns>
        /// <seealso cref="EndShareProject"/>
        public IAsyncResult BeginShareProject(Project p, IEnumerable <string> emails, AsyncCallback callback, object stateObject)
        {
            AsyncResultNoResult <Project, IEnumerable <string> > ar = new AsyncResultNoResult <Project, IEnumerable <string> >(callback, stateObject, p, emails);

            ThreadPool.QueueUserWorkItem(ShareProjectAsyncHelper, ar);

            return(ar);
        }
示例#8
0
        /// <summary>
        /// Remove a project asynchronously, according to the APM (Asynchrnonous Programming Model).
        /// </summary>
        /// <param name="p">Project to remove</param>
        /// <param name="callback">Callback called upon finish</param>
        /// <param name="state">State object, passed to callback.</param>
        /// <returns>IAsyncResult used by EndRemoveProject</returns>
        /// <seealso cref="EndRemoveProject"/>
        public IAsyncResult BeginRemoveProject(Project p, AsyncCallback callback, object state)
        {
            AsyncResultNoResult <Project> ar = new AsyncResultNoResult <Project>(callback, state, p);

            ThreadPool.QueueUserWorkItem(RemoveProjectAsyncHelper, ar);

            return(ar);
        }
示例#9
0
        public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
        {
            this.LockHeaders();
            var asyncResult = new AsyncResultNoResult(callback, state);

            asyncResult.SetAsCompleted(null, true);
            return(asyncResult);
        }
示例#10
0
        void PortAcceptCallback(IAsyncResult ar)
        {
            AsyncResult_BABc    arSac; // Call SetAsCompleted outside the lock.
            Exception           exSac;
            AsyncResultNoResult ar2  = (AsyncResultNoResult)ar;
            CommonRfcommStream  port = (CommonRfcommStream)ar2.AsyncState;

            lock (m_key) {
                try {
                    port.EndAccept(ar2);
                    exSac = null;
                } catch (Exception ex) {
                    if (IsDisposed)
                    {
                        Debug.WriteLine("INFO PortAccepted was an error (Stopped: true): " + ex.Message);
                    }
                    else
                    {
                        Debug.WriteLine("PortAccepted was an error: " + ex.ToString());
                    }
                    if (IsDisposed)
                    {
                        return;
                    }
                    exSac = ex;
                }
                bool found = m_listening.Remove(port);
                Debug.Assert(found, "NOT found");
                if (m_callers.Count > 0)
                {
                    // Release one Accept immediately
                    Debug.Assert(m_accepted.Count == 0, "Why clients waiting when also pending accepted!?!");
                    arSac = m_callers.Dequeue();
                    Debug.WriteLine("PortAccepted Dequeued a caller");
                }
                else
                {
                    // Queue the new port for later accept call
                    if (exSac != null)   // DEBUG
                    {
                    }
                    m_accepted.Enqueue(new AcceptedPort(port, exSac));
                    arSac = null;
                    Debug.WriteLine("PortAccepted Enqueued");
                }
                StartEnoughNewListenerPort_inLock();
            }// lock
            // Raise events if any.
            var args = new RaiseAcceptParams
            {
                arSac = arSac,
                exSac = exSac,
                port  = port
            };

            ThreadPool.QueueUserWorkItem(RaiseAccept, args);
        }
示例#11
0
        public IAsyncResult BeginConnect(string command, AsyncCallback callback, object state, params object[] arguments)
        {
            this._uri       = new System.Uri(command);
            this._arguments = arguments;
            AsyncResultNoResult result = new AsyncResultNoResult(callback, state);

            ThreadPool.QueueUserWorkItem(new WaitCallback(this.DoConnect), result);
            return(result);
        }
示例#12
0
 /// <summary>
 /// Begins an asynchronous operation to invoke clients with parameters and callback.
 /// </summary>
 /// <param name="asyncCallback">The AsyncCallback delegate.</param>
 /// <param name="method">Method name.</param>
 /// <param name="arguments">Invocation parameters passed to the method.</param>
 /// <param name="callback">Callback used to handle return values.</param>
 /// <param name="ignoreSelf">Current client shoud be ignored.</param>
 /// <param name="targetScope">Invoke clients subscribed to the specified Scope.</param>
 /// <returns>An IAsyncResult that references the asynchronous invocation.</returns>
 /// <remarks>
 /// <para>
 /// The <i>asyncCallback</i> delegate identifies the callback invoked when the messages are sent, the <i>callback</i> object identifies the callback handling client responses.
 /// </para>
 /// <para>
 /// You can create a callback method that implements the AsyncCallback delegate and pass its name to the BeginInvokeClients method.
 /// </para>
 /// <para>
 /// Your callback method should invoke the EndInvokeClients method. When your application calls BeginInvokeClients, the system will use a separate thread to execute the specified callback method, and will block on EndInvokeClients until the clients are invoked successfully or throws an exception.
 /// </para>
 /// </remarks>
 protected IAsyncResult BeginInvokeClients(AsyncCallback asyncCallback, string method, object[] arguments, IPendingServiceCallback callback, bool ignoreSelf, IScope targetScope)
 {
     // Create IAsyncResult object identifying the asynchronous operation
     AsyncResultNoResult ar = new AsyncResultNoResult(asyncCallback, new InvokeData(FluorineContext.Current, method, arguments, callback, ignoreSelf, targetScope));
     // Use a thread pool thread to perform the operation
     FluorineFx.Threading.ThreadPoolEx.Global.QueueUserWorkItem(new System.Threading.WaitCallback(OnBeginInvokeClients), ar);
     // Return the IAsyncResult to the caller
     return ar;
 }
示例#13
0
        /// <summary>
        /// Begins an asynchronous operation to push a message to the specified clients (subscribers).
        /// </summary>
        /// <param name="asyncCallback">The AsyncCallback delegate.</param>
        /// <param name="subscribers">Collection of subscribers.</param>
        /// <param name="message">The Message to push to the subscribers.</param>
        /// <returns>An IAsyncResult that references the asynchronous invocation.</returns>
        /// <remarks>
        /// <para>
        /// The Collection of subscribers is a collection of client Id strings.
        /// </para>
        /// <para>
        /// You can create a callback method that implements the AsyncCallback delegate and pass its name to the BeginPushMessageToClients method.
        /// </para>
        /// <para>
        /// Your callback method should invoke the EndPushMessageToClients method. When your application calls EndPushMessageToClients, the system will use a separate thread to execute the specified callback method, and will block on EndPushMessageToClients until the message is pushed successfully or throws an exception.
        /// </para>
        /// </remarks>
        public IAsyncResult BeginPushMessageToClients(AsyncCallback asyncCallback, ICollection subscribers, IMessage message)
        {
            // Create IAsyncResult object identifying the asynchronous operation
            AsyncResultNoResult ar = new AsyncResultNoResult(asyncCallback, new PushData(FluorineContext.Current, subscribers, message));

            // Use a thread pool thread to perform the operation
            FluorineFx.Threading.ThreadPoolEx.Global.QueueUserWorkItem(new System.Threading.WaitCallback(OnBeginPushMessageToClients), ar);
            // Return the IAsyncResult to the caller
            return(ar);
        }
示例#14
0
        /// <summary>
        /// Asynchronous version of Connect.
        /// </summary>
        /// <param name="asyncResult"></param>
        public void EndConnect(IAsyncResult asyncResult)
        {
            AsyncResultNoResult ar = asyncResult as AsyncResultNoResult;

            // Wait for operation to complete, then return result or throw exception
            if (ar != null)
            {
                ar.EndInvoke();
            }
        }
示例#15
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);
            }
        }
示例#16
0
        void Connect_ConnCallback(IAsyncResult ar)
        {
            BeginConnectState   bsState      = (BeginConnectState)ar.AsyncState;
            AsyncResultNoResult arCliConnect = bsState.arCliConnect;

            try {
                ConnEndConnect(ar);
                Connect_SetAsCompleted_CompletedSyncFalse(arCliConnect, null);
            } catch (Exception ex) {
                Connect_SetAsCompleted_CompletedSyncFalse(arCliConnect, ex);
            }
        }
示例#17
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);
            }
        }
示例#18
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);
            }
        }
示例#19
0
        /// <summary>
        /// Asynchronous version of Connect.
        /// </summary>
        /// <param name="command">Command.</param>
        /// <param name="callback">Callback object.</param>
        /// <param name="state"></param>
        /// <param name="arguments">Optional parameters of any type to be passed to the application specified in command.</param>
        /// <returns></returns>
        public IAsyncResult BeginConnect(string command, AsyncCallback callback, object state, params object[] arguments)
        {
            _uri       = new Uri(command);
            _arguments = arguments;
            // Create IAsyncResult object identifying the asynchronous operation
            AsyncResultNoResult ar = new AsyncResultNoResult(callback, state);

            // Use a thread pool thread to perform the operation
            System.Threading.ThreadPool.QueueUserWorkItem(DoConnect, ar);
            // Return the IAsyncResult to the caller
            return(ar);
        }
示例#20
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);
        }
示例#22
0
        public IAsyncResult BeginConnect(BluetoothEndPoint remoteEP, AsyncCallback requestCallback, object state)
        {
            // Just in case the user modifies the original endpoint or address!!!
            BluetoothEndPoint rep2 = (BluetoothEndPoint)remoteEP.Clone();
            //
            AsyncResultNoResult arConnect     = new AsyncResultNoResult(requestCallback, state);
            AsyncResultNoResult origArConnect = System.Threading.Interlocked.CompareExchange(
                ref m_arConnect, arConnect, null);

            if (origArConnect != null)
            {
                throw new InvalidOperationException("Another Connect operation is already in progress.");
            }
            BeginFillInPort(rep2, Connect_FillInPortCallback,
                            new BeginConnectState(rep2, arConnect));
            return(arConnect);
        }
示例#23
0
        new public static void End(IAsyncResult result, object owner, string operationId)
        {
            BitCoinResult asyncResult = result as BitCoinResult;

            if (asyncResult == null)
            {
                throw new ArgumentException(
                          "Result passed represents an operation not supported " +
                          "by this framework.",
                          "result");
            }

            // Wait until operation has completed
            AsyncResultNoResult.End(result, owner, operationId);

            // Write the result to client (if above didn't throw)
            if (asyncResult.m_result != null && asyncResult.m_context.Response.IsClientConnected)
            {
                try
                {
                    var outgoingResponse = asyncResult.m_context.Response;

                    // write the response to stream
                    outgoingResponse.ContentEncoding = Encoding.UTF8;
                    outgoingResponse.ContentType     = asyncResult.m_result.ContentType;
                    outgoingResponse.StatusCode      = asyncResult.m_result.HttpStatusCode;

                    if (asyncResult.m_result.HttpStatusCode == 401)
                    {
                        outgoingResponse.AddHeader("WWW-Authenticate",
                                                   "BASIC Realm=TopBit API (http://api.topb.it)");
                    }

                    if (outgoingResponse.StatusCode == 200)
                    {
                        outgoingResponse.Write(asyncResult.m_result.ToJson());
                    }

                    outgoingResponse.End();
                }
                catch (Exception)
                {
                    // socket connection from mining client is interrupted.
                }
            }
        }
示例#24
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);
            }
        }
示例#25
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);
            }
        }
示例#26
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);
                }
            }
        }
示例#27
0
        void Connect_FillInPortCallback(IAsyncResult ar)
        {
            BeginConnectState   bcState   = (BeginConnectState)ar.AsyncState;
            AsyncResultNoResult arConnect = bcState.arCliConnect;

            try {
                BluetoothEndPoint remoteEpWithPort = EndFillInPort(ar);
                if (arConnect.IsCompleted)
                {
                    // User called Close/Dispose when we were in (slow!) SDP lookup.
                    Debug.Assert(m_disposed, "arConnect.IsCompleted but NOT m_cancelled");
                    return;
                }
                _remotePort = remoteEpWithPort.Port;
                Debug.Assert(_remotePort != -1 && _remotePort != 0, "port is 'empty' is: " + _remotePort);
                ConnBeginConnect(remoteEpWithPort, Connect_ConnCallback, bcState);
            } catch (Exception ex) {
                Connect_SetAsCompleted_CompletedSyncFalse(arConnect, ex);
            }
        }
示例#28
0
        protected //???
        void Connect_SetAsCompleted_CompletedSyncFalse(AsyncResultNoResult arConnect_Debug, Exception ex)
        {
            // Read state to check not already completed (is null).  And set it to null always.
            AsyncResultNoResult arOrig = Interlocked.Exchange(ref m_arConnect, null);

            if (arOrig == null)
            {
                // We use m_arConnect being null as an indication that it is already SetAsCompleted.
                Debug.Assert(m_disposed, "arConnect is already IsCompleted but NOT m_cancelled");
                Debug.Assert(arConnect_Debug == null || arConnect_Debug.IsCompleted, "NOT arConnect.IsCompleted: How!? Different instances?");
#if CODE_ANALYSIS
                Trace.Assert(m_disposed, "arConnect is already IsCompleted but NOT m_cancelled");
#endif
            }
            else
            {
                Debug.Assert(arConnect_Debug == null || arConnect_Debug == arOrig, "arConnect != m_arConnect: should only be one instance!");
                // Set!
                var args = new RaiseConnectParams {
                    arOrig = arOrig, ex = ex
                };
                ThreadPool.QueueUserWorkItem(RaiseConnect, args);
            }
        }
示例#29
0
        /// <summary>
        /// Start saving a document asynchronously in accordance with the Asynchronous Programming Model.
        /// </summary>
        /// <param name="d">Document to save</param>
        /// <param name="callback">Callback called when document saving finishes</param>
        /// <param name="state">State object, passed to callback</param>
        /// <returns>IAsyncResult for EndSaveDocument</returns>
        /// <seealso cref="EndSaveDocument"/>
        public IAsyncResult BeginSaveDocument(Document d, AsyncCallback callback, object state)
        {
            AsyncResultNoResult<Document> ar = new AsyncResultNoResult<Document>(callback, state, d);
            ThreadPool.QueueUserWorkItem(SaveDocumentAsyncHelper, ar);

            return ar;
        }
 public override IAsyncResult BeginGetResponse(AsyncCallback callback, object state)
 {
     this.LockHeaders();
     var asyncResult = new AsyncResultNoResult(callback, state);
     asyncResult.SetAsCompleted(null, true);
     return asyncResult;
 }
示例#31
0
		/// <summary>
		/// Begins an asynchronous operation to push a message to the specified clients (subscribers).
		/// </summary>
		/// <param name="asyncCallback">The AsyncCallback delegate.</param>
		/// <param name="subscribers">Collection of subscribers.</param>
		/// <param name="message">The Message to push to the subscribers.</param>
		/// <returns>An IAsyncResult that references the asynchronous invocation.</returns>
		/// <remarks>
		/// <para>
		/// The Collection of subscribers is a collection of client Id strings.
		/// </para>
		/// <para>
		/// You can create a callback method that implements the AsyncCallback delegate and pass its name to the BeginPushMessageToClients method.
		/// </para>
		/// <para>
		/// Your callback method should invoke the EndPushMessageToClients method. When your application calls EndPushMessageToClients, the system will use a separate thread to execute the specified callback method, and will block on EndPushMessageToClients until the message is pushed successfully or throws an exception.
		/// </para>
		/// </remarks>
		public IAsyncResult BeginPushMessageToClients(AsyncCallback asyncCallback, ICollection subscribers, IMessage message) {
			// Create IAsyncResult object identifying the asynchronous operation
			AsyncResultNoResult ar = new AsyncResultNoResult(asyncCallback, new PushData(FluorineContext.Current, subscribers, message));
			// Use a thread pool thread to perform the operation
			GodLesZ.Library.Amf.Threading.ThreadPoolEx.Global.QueueUserWorkItem(new System.Threading.WaitCallback(OnBeginPushMessageToClients), ar);
			// Return the IAsyncResult to the caller
			return ar;
		}
示例#32
0
        /// <summary>
        /// Wait for asynchronous project sharing to finish, then return it
        /// </summary>
        /// <param name="asyncResult">IAsyncResult from BeginShareProject</param>
        /// <seealso cref="BeginShareProject"/>
        public void EndShareProject(IAsyncResult asyncResult)
        {
            AsyncResultNoResult <Project, IEnumerable <string> > ar = (AsyncResultNoResult <Project, IEnumerable <string> >)asyncResult;

            ar.EndInvoke();
        }
示例#33
0
		/// <summary>
		/// Begins an asynchronous operation to invoke a service using service call object and channel.
		/// </summary>
		/// <param name="asyncCallback">The AsyncCallback delegate.</param>
		/// <param name="serviceCall">Service call object.</param>
		/// <param name="channel">Channel to use.</param>
		/// <returns>An IAsyncResult that references the asynchronous invocation.</returns>
		/// <remarks>
		/// <para>
		/// You can create a callback method that implements the AsyncCallback delegate and pass its name to the BeginInvoke method.
		/// </para>
		/// <para>
		/// Your callback method should invoke the EndInvoke method. When your application calls BeginInvoke, the system will use a separate thread to execute the specified callback method, and will block on EndInvoke until the client is invoked successfully or throws an exception.
		/// </para>
		/// </remarks>        
		public IAsyncResult BeginInvoke(AsyncCallback asyncCallback, IServiceCall serviceCall, byte channel) {
			// Create IAsyncResult object identifying the asynchronous operation
			AsyncResultNoResult ar = new AsyncResultNoResult(asyncCallback, new InvokeData(FluorineContext.Current, serviceCall, channel));
			// Use a thread pool thread to perform the operation
			GodLesZ.Library.Amf.Threading.ThreadPoolEx.Global.QueueUserWorkItem(new System.Threading.WaitCallback(OnBeginInvoke), ar);
			// Return the IAsyncResult to the caller
			return ar;
		}
示例#34
0
        /// <summary>
        /// Start removing a folder asynchronously in accordance to the Asynchronous Programming Model.
        /// </summary>
        /// <param name="f">Folder to remove</param>
        /// <param name="callback">Callback called when folder has been removed</param>
        /// <param name="state">State object (passed to callback)</param>
        /// <returns>IAsyncResult for EndRemoveFolder</returns>
        /// <seealso cref="EndRemoveFolder"/>
        public IAsyncResult BeginRemoveFolder(Folder f, AsyncCallback callback, object state)
        {
            AsyncResultNoResult<Folder> ar = new AsyncResultNoResult<Folder>(callback, state, f);
            ThreadPool.QueueUserWorkItem(RemoveFolderAsyncHelper, ar);

            return ar;
        }
示例#35
0
 public BeginConnectState(BluetoothEndPoint inputEP, AsyncResultNoResult arCliConnect)
 {
     //this.inputEP = inputEP;
     this.arCliConnect = arCliConnect;
 }
示例#36
0
        /// <summary>
        /// Remove a project asynchronously, according to the APM (Asynchrnonous Programming Model).
        /// </summary>
        /// <param name="p">Project to remove</param>
        /// <param name="callback">Callback called upon finish</param>
        /// <param name="state">State object, passed to callback.</param>
        /// <returns>IAsyncResult used by EndRemoveProject</returns>
        /// <seealso cref="EndRemoveProject"/>
        public IAsyncResult BeginRemoveProject(Project p, AsyncCallback callback, object state)
        {
            AsyncResultNoResult<Project> ar = new AsyncResultNoResult<Project>(callback, state, p);
            ThreadPool.QueueUserWorkItem(RemoveProjectAsyncHelper, ar);

            return ar;
        }
示例#37
0
		/// <summary>
		/// Begins an asynchronous operation to invoke clients with parameters and callback.
		/// </summary>
		/// <param name="asyncCallback">The AsyncCallback delegate.</param>
		/// <param name="method">Method name.</param>
		/// <param name="arguments">Invocation parameters passed to the method.</param>
		/// <param name="callback">Callback used to handle return values.</param>
		/// <param name="ignoreSelf">Current client shoud be ignored.</param>
		/// <param name="targetScope">Invoke clients subscribed to the specified Scope.</param>
		/// <returns>An IAsyncResult that references the asynchronous invocation.</returns>
		/// <remarks>
		/// <para>
		/// The <i>asyncCallback</i> delegate identifies the callback invoked when the messages are sent, the <i>callback</i> object identifies the callback handling client responses.
		/// </para>
		/// <para>
		/// You can create a callback method that implements the AsyncCallback delegate and pass its name to the BeginInvokeClients method.
		/// </para>
		/// <para>
		/// Your callback method should invoke the EndInvokeClients method. When your application calls BeginInvokeClients, the system will use a separate thread to execute the specified callback method, and will block on EndInvokeClients until the clients are invoked successfully or throws an exception.
		/// </para>
		/// </remarks>
		protected IAsyncResult BeginInvokeClients(AsyncCallback asyncCallback, string method, object[] arguments, IPendingServiceCallback callback, bool ignoreSelf, IScope targetScope) {
			// Create IAsyncResult object identifying the asynchronous operation
			AsyncResultNoResult ar = new AsyncResultNoResult(asyncCallback, new InvokeData(FluorineContext.Current, method, arguments, callback, ignoreSelf, targetScope));
			// Use a thread pool thread to perform the operation
			GodLesZ.Library.Amf.Threading.ThreadPoolEx.Global.QueueUserWorkItem(new System.Threading.WaitCallback(OnBeginInvokeClients), ar);
			// Return the IAsyncResult to the caller
			return ar;
		}
示例#38
0
        /// <summary>
        /// Starts sharing a project using APM.
        /// </summary>
        /// <param name="p">Project to share</param>
        /// <param name="emails">Emails to share the project with</param>
        /// <param name="callback">Callback called upon conclusion of sharing</param>
        /// <param name="stateObject">state object woopdashoopfloop</param>
        /// <returns>IAsyncResult for EnShareProject</returns>
        /// <seealso cref="EndShareProject"/>
        public IAsyncResult BeginShareProject(Project p, IEnumerable<string> emails, AsyncCallback callback, object stateObject)
        {
            AsyncResultNoResult<Project, IEnumerable<string>> ar = new AsyncResultNoResult<Project, IEnumerable<string>>(callback, stateObject, p, emails);
            ThreadPool.QueueUserWorkItem(ShareProjectAsyncHelper, ar);

            return ar;
        }
示例#39
0
 public override IAsyncResult BeginGetRequestStream(AsyncCallback callback, object state)
 {
     var result = new AsyncResultNoResult(callback, state);
     result.SetAsCompleted(null, true);
     return result;
 }