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; } } }
private void NotifyOperationCompleted(IMySqlActiveOperation activeOperation, out Exception completionException) { completionException = null; try { using (MySqlCommand Command = ActiveOperationTable[activeOperation]) { ActiveOperationTable.Remove(activeOperation); IResultInternal Result = activeOperation.ResultBase; string Diagnostic = activeOperation.MySqlFinalizerBase(Command, Result); if (Result.IsCompletedSynchronously) { Diagnostic += " [SYNCHRONOUS]"; } TraceCommandEnd(Command, Diagnostic); } } #if TRACE catch (ApplicationException) { throw; } #endif catch (MySqlException e) { TraceMySqlException(e); } catch (Exception e) { completionException = e; TraceException(e); } }