/// <summary> /// Create a new Scheduler to process the given client bus. /// </summary> /// <param name="bus">The bus to listen to.</param> public Scheduler(ClientBus bus) { _Bus = bus; _CancelExecutionEngine = new CancellationTokenSource(); var token = _CancelExecutionEngine.Token; Task.Factory.StartNew(() => { while (!token.IsCancellationRequested) { Current = null; _RunsToGo.Wait(token); if (token.IsCancellationRequested) { return; } if (_ToRun.TryDequeue(out var context)) { try { Current = context; context.RunInNewProcess(_Bus); } catch (Exception e) { _Bus.ModelRunFailed(context.ID, e.Message, e.StackTrace); } } Interlocked.MemoryBarrier(); } }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
private Stream?CreateRunBusLocal(ClientBus clientBus) { var pipeName = Guid.NewGuid().ToString(); string?error = null; Stream?clientToRunStream = null; CreateStreams.CreateNewNamedPipeHost(pipeName, out clientToRunStream, ref error, () => { clientBus.StartProcessingRequestFromRun(ID, clientToRunStream !); if (CreateStreams.CreateNamedPipeClient(pipeName, out var runToClientStream, ref error)) { Task.Factory.StartNew(() => { using var rb = new RunBus(ID, runToClientStream !, true, _runtime); rb.ProcessRequests(); }, TaskCreationOptions.LongRunning); } });