private void ExecuteOperation() { WaitHandle[] ThreadHandles = new WaitHandle[] { NewOperationEvent, ShutdownEvent }; bool Exit = false; while (!Exit) { int ThreadWaitResult = WaitHandle.WaitAny(ThreadHandles, Timeout.InfiniteTimeSpan); if (ThreadWaitResult == 0) { IActiveOperation[] ActiveOperations = new IActiveOperation[ActiveOperationTable.Count]; WaitHandle[] OperationHandles = new WaitHandle[ActiveOperationTable.Count + 1]; OperationHandles[0] = ShutdownEvent; int n = 0; foreach (IActiveOperation ActiveOperation in ActiveOperationTable) { ActiveOperations[n] = ActiveOperation; OperationHandles[n + 1] = ActiveOperation.ResultBase.AsyncResult.AsyncWaitHandle; n++; } int OperationWaitResult = WaitHandle.WaitAny(OperationHandles, TimeSpan.FromSeconds(1.0)); if (OperationWaitResult == WaitHandle.WaitTimeout) { NewOperationEvent.Set(); } else if (OperationWaitResult > 0 && OperationWaitResult <= OperationHandles.Length) { IActiveOperation ActiveOperation = ActiveOperations[OperationWaitResult - 1]; ActiveOperationTable.Remove(ActiveOperation); Connector.NotifyOperationCompleted(ActiveOperation, out Exception CompletionException); if (LastCompletionException == null && CompletionException != null) { LastCompletionException = CompletionException; } } else { Exit = true; } } else { Exit = true; } } }
public override void NotifyOperationCompleted(IActiveOperation activeOperation, out Exception completionException) { Debug.Assert(activeOperation is IMySqlActiveOperation); if (activeOperation is IMySqlActiveOperation AsMySqlActiveOperation) { NotifyOperationCompleted(AsMySqlActiveOperation, out completionException); } else { completionException = null; } }
/// <summary> /// Executes a request to delete rows in a table, with constraints. /// This is the synchronous implementation. /// </summary> /// <parameters> /// <param name="context">Description of the request.</param> /// </parameters> /// <returns> /// The request result. /// </returns> protected virtual IDeleteResult Execute(IDeleteContext context) { if (!IsOperationThreadStarted) { return(new DeleteResult(false, ResultError.ErrorFatalNoOperationThread)); } IActiveOperation <IDeleteResultInternal> ActiveOperation = Connector.Delete(context); IDeleteResultInternal Result = ActiveOperation.Result; FinalizeOrQueue(ActiveOperation); return(Result); }
/// <summary> /// Executes a request to insert several values in a table. /// This is the synchronous implementation. /// </summary> /// <parameters> /// <param name="context">Description of the request.</param> /// </parameters> /// <returns> /// The request result. /// </returns> protected virtual IInsertResult Execute(IInsertContext context) { if (!IsOperationThreadStarted) { return(new InsertResult(false, ResultError.ErrorFatalNoOperationThread)); } if (context.RowCount == 0 || context.EntryList.Count == 0) { return(new InsertResult(true, ResultError.ErrorNone)); } IActiveOperation <IInsertResultInternal> ActiveOperation = Connector.Insert(context); IInsertResultInternal Result = ActiveOperation.Result; FinalizeOrQueue(ActiveOperation); return(Result); }
private void FinalizeOrQueue(IActiveOperation activeOperation) { IResultInternal Result = activeOperation.ResultBase; if (Result.IsStarted) { Result.CheckIfCompletedSynchronously(out bool IsCompletedSynchronously); if (IsCompletedSynchronously) { Connector.NotifyOperationCompleted(activeOperation, out Exception CompletionException); if (CompletionException != null) { throw CompletionException; } } else { ActiveOperationTable.Add(activeOperation); NewOperationEvent.Set(); Result.WaitCompleted(); } } }
public abstract void NotifyOperationCompleted(IActiveOperation activeOperation, out Exception completionException);