private void CallbackRefreshTables(AsyncCallbackState callbackState) { var data = (Tuple <IDBProvider, IConnectionInfo>)callbackState.State; IDBProvider dbProvider = data.Item1; IConnectionInfo connectionInfo = data.Item2; if (dbProvider.IsConnected) { dbProvider.Disconnect(); } bool connectResult = dbProvider.Connect(connectionInfo); if (connectResult) { Server server = new Server(connectionInfo.ServerName); Database database = new Database(connectionInfo.DatabaseName, server); bool refresResult = dbProvider.Refresh(database, LoadingMode.RecursiveAllLevels); if (refresResult) { callbackState.InvokeOnUI(delegate(object state) { Database db = (Database)state; PopulateTables(db); }, database); } } }
public static IAsyncResult BeginInvokeEx(this AsyncCallback cb, IAsyncResult asyncResult, AsyncCallback callback, object @object) { var newAr = new AsyncResult(cb, @object); var acs = new AsyncCallbackState(asyncResult, callback, newAr); CrestronInvoke.BeginInvoke(DoCallback, acs); return(newAr); }
public WorkflowOperationAsyncResult(WorkflowOperationInvoker workflowOperationInvoker, WorkflowDurableInstance workflowDurableInstance, object[] inputs, AsyncCallback callback, object state, long time) : base(callback, state) { if (inputs == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("inputs"); } if (workflowDurableInstance == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("workflowDurableInstance"); } if (workflowOperationInvoker == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("workflowOperationInvoker"); } string queueName; WorkflowRequestContext workflowRequestContext = new WorkflowRequestContext( this, inputs, GetContextProperties()); queueName = workflowOperationInvoker.StaticQueueName; if (workflowRequestContext.ContextProperties.Count > 1) //DurableDispatchContextProperty. { queueName = QueueNameHelper.Create(workflowOperationInvoker.StaticQueueName, workflowRequestContext.ContextProperties); } WorkflowInstance workflowInstance = workflowDurableInstance.GetWorkflowInstance (workflowOperationInvoker.CanCreateInstance); AsyncCallbackState callbackState = new AsyncCallbackState(workflowRequestContext, workflowInstance, workflowOperationInvoker.DispatchRuntime.SynchronizationContext, workflowOperationInvoker.InstanceLifetimeManager, queueName); this.isOneway = workflowOperationInvoker.IsOneWay; this.instanceIdGuid = workflowInstance.InstanceId; this.time = time; ActionItem.Schedule(waitCallback, callbackState); if (DiagnosticUtility.ShouldTraceVerbose) { string traceText = SR2.GetString(SR2.WorkflowOperationInvokerItemQueued, this.InstanceId, queueName); TraceUtility.TraceEvent(TraceEventType.Verbose, TraceCode.WorkflowOperationInvokerItemQueued, SR.GetString(SR.TraceCodeWorkflowOperationInvokerItemQueued), new StringTraceRecord("ItemDetails", traceText), this, null); } }
private static void SendCallback(IAsyncResult ar) { AsyncCallbackState <int> state = ar.AsyncState as AsyncCallbackState <int>; try { int sent = state.Socket.EndSend(ar); state.Callback?.Invoke(sent); } catch (Exception ex) { state.Callback?.Invoke(0); } }
private static void AsyncConnectCallback(IAsyncResult ar) { AsyncCallbackState <TcpSocket> asyncState = ar.AsyncState as AsyncCallbackState <TcpSocket>; try { asyncState.Socket.EndConnect(ar); asyncState.Callback?.Invoke(SetupClientToken(asyncState.Socket)); } catch (Exception) { asyncState.Callback?.Invoke(null); } }
static void DoWork(object state) { if (state == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("state"); } AsyncCallbackState callbackState = (AsyncCallbackState)state; bool executingWork = false; try { //If SyncContext is enabled //We have to do another post to get to correct thread. if (callbackState.SynchronizationContext != null) { SynchronizationContext synchronizationContext = callbackState.SynchronizationContext; callbackState.SynchronizationContext = null; SynchronizationContextWorkflowSchedulerService.SynchronizationContextPostHelper.Post( synchronizationContext, WorkflowOperationAsyncResult.sendOrPostCallback, callbackState); } else //We are in correct thread to do the work. { using (new WorkflowDispatchContext(true)) { callbackState.WorkflowRequestContext.SetOperationBegin(); executingWork = true; if (callbackState.WorkflowInstanceLifeTimeManager != null) { callbackState.WorkflowInstanceLifeTimeManager.NotifyMessageArrived(callbackState.WorkflowInstance.InstanceId); } callbackState.WorkflowInstance.EnqueueItemOnIdle( callbackState.QueueName, callbackState.WorkflowRequestContext, null, null); } } } catch (QueueException e) { WorkflowOperationFault operationFault = new WorkflowOperationFault(e.ErrorCode); try { if (callbackState.WorkflowInstanceLifeTimeManager != null) { callbackState.WorkflowInstanceLifeTimeManager.ScheduleTimer(callbackState.WorkflowInstance.InstanceId); } callbackState.WorkflowRequestContext.SendFault(new FaultException(operationFault), null); } catch (Exception unhandled) { if (Fx.IsFatal(unhandled)) { throw; } // ignore exception; we made best effort to propagate the exception back to the invoker thread } } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } try { if (callbackState.WorkflowInstanceLifeTimeManager != null) { callbackState.WorkflowInstanceLifeTimeManager.ScheduleTimer(callbackState.WorkflowInstance.InstanceId); } //We should field only user code exception; Everything else should go abort path. callbackState.WorkflowRequestContext.GetAsyncResult().SendFault(e, null); } catch (Exception e1) { if (Fx.IsFatal(e1)) { throw; } // ignore exception; we made best effort to propagate the exception back to the invoker thread } } finally { try { if (executingWork) { callbackState.WorkflowRequestContext.SetOperationCompleted(); } } catch (Exception e1) { if (Fx.IsFatal(e1)) { throw; } // ignore exception; we made best effort to propagate the exception back to the invoker thread } } } }