//-------- 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); }
/// <summary> /// Helper for asynchronously removing a folder. /// </summary> /// <param name="asyncResult">AsyncResultNoResult<Folder></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); } }
/// <summary> /// Helper method to asynchronously save documents /// </summary> /// <param name="asyncResult">AsyncResultNoResult<Document></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); } }
/// <summary> /// Helper facilitating asynchronous sharing of projects /// </summary> /// <param name="asyncResult">AsyncResultNoResult<Project, IEnumerable<string>></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); } }
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); }
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); }
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); } }
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); } }
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); } } }
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; }