public void OnContextDestroyed() { DoofusesStandardSchedulers.StopAndCleanupAllDefaultSchedulers(); TaskRunner.Stop(); GC.Collect(); GC.WaitForPendingFinalizers(); _enginesRoot?.Dispose(); }
public void OnContextDestroyed() { BoxtopiaSchedulers.StopAllCoroutines(); TaskRunner.Stop(); GC.Collect(); GC.WaitForPendingFinalizers(); _enginesRoot.Dispose(); }
public override void When() { _runner = new TaskRunner(_someKey, _getTaskFunc, _someSpinInterval, HandleExceptionFunc, _cancellationTokenSource.Token); _result = _runner.Run(); Task.Delay(GetTimeoutFor(expectedExecutionTimes: 5, interval: _someSpinInterval)).Wait(); _runner.Stop(); _processException = Catch.Exception(() => _result.Wait() ); }
/// <summary> /// 重写基类的虚函数,用于开始流传输 /// </summary> /// <param name="model">存储了各道信息的Json文件的序列化对象</param> /// <param name="token">是否取消作业的凭证</param> /// <param name="interval">模拟数据生成时间间隔</param> /// <returns></returns> public override async Task Start(Simulation model, CancellationToken token, int interval = 5000) { Model = model;//基类中定义 public Models.Simulation Model { get; protected set; } using (Client = Model.EtpConnection.CreateEtpClient(Model.Name, Model.Version)) { ///<summary> ///指定客户端的职能:生产数据流 /// </summary> Client.Register <IChannelStreamingProducer, ChannelStreamingProducerHandler>(); ///<remarks> /// 配置客户端生成数据时操作 /// </remarks> Client.Handler <IChannelStreamingProducer>().OnStart += OnStart; //线程启动事件 Client.Handler <IChannelStreamingProducer>().OnChannelDescribe += OnChannelDescribe; //获取道头描述事件 Client.Handler <IChannelStreamingProducer>().OnChannelStreamingStart += OnChannelStreamingStart; //传输流开始事件 Client.Handler <IChannelStreamingProducer>().OnChannelStreamingStop += OnChannelStreamingStop; //传输流结束事件 ///<remarks> ///For simple streaming: //• always sends all of its channels. //• The producer MUST NOT send any data until the Start message is received.The Start message //indicates that the consumer is ready to receive data and establishes any rate-control or throttling parameters. //• The producer sends at least one ChannelMetadata message, indicating the channels it will stream. //• After this, the producer can begin streaming ChannelData. //When a producer identifies itself as a SimpleStreamer, the producer and the consumer MUST NOT use //any messages other than Start, ChannelMetadata and ChannelData. /// </remarks> Client.Handler <IChannelStreamingProducer>().IsSimpleStreamer = Model.IsSimpleStreamer; Client.Handler <IChannelStreamingProducer>().DefaultDescribeUri = EtpUri.RootUri; Client.SocketClosed += OnClientSocketClosed; //绑定输出路径 Client.Output = Log; //开启客户端 Client.Open(); //不停的生成数据并上传到服务器中 while (true) { if (token.IsCancellationRequested) { break; } try { //在新的线程里开始任务 await Task.Delay(interval, token); } catch (TaskCanceledException) { break; } } TaskRunner.Stop(); Client.Handler <ICoreClient>().CloseSession("Streaming stopped"); } }
public static void StopAllCoroutines() { ExtraLean.BoxtopiaSchedulers.UIScheduler.Stop(); ExtraLean.BoxtopiaSchedulers.InputScheduler.Stop(); ExtraLean.BoxtopiaSchedulers.CharacterUpdateScheduler.Stop(); ExtraLean.BoxtopiaSchedulers.CharacterLateUpdateScheduler.Stop(); Lean.BoxtopiaSchedulers.UIScheduler.Stop(); Lean.BoxtopiaSchedulers.UserScheduler.Stop(); Lean.BoxtopiaSchedulers.ResourceScheduler.Stop(); TaskRunner.Stop(); }
public override async Task Start(Models.Simulation model, CancellationToken token, int interval = 5000) { Model = model; Simulator = new Etp12Simulator(model); _log.Debug($"Establishing ETP connection for {Model.EtpConnection}"); using (Client = Model.EtpConnection.CreateEtpClient(Model.Name, Model.Version)) { Client.Register <IChannelStreamingProducer, ChannelStreamingProducerHandler>(); Client.Handler <IChannelStreamingProducer>().OnStartStreaming += OnStartStreaming; Client.Handler <IChannelStreamingProducer>().OnStopStreaming += OnStopStreaming; //Client.Handler<IChannelStreamingProducer>().OnStart += OnStart; //Client.Handler<IChannelStreamingProducer>().OnChannelDescribe += OnChannelDescribe(); //Client.Handler<IChannelStreamingProducer>().OnChannelStreamingStart += OnChannelStreamingStart; //Client.Handler<IChannelStreamingProducer>().OnChannelStreamingStop += OnChannelStreamingStop; //Client.Handler<IChannelStreamingProducer>().IsSimpleStreamer = Model.IsSimpleStreamer; //Client.Handler<IChannelStreamingProducer>().DefaultDescribeUri = EtpUri.RootUri; Client.SocketClosed += OnClientSocketClosed; Client.Output = Log; if (!await Client.OpenAsync()) { Log("Error opening web socket connection"); return; } while (true) { if (token.IsCancellationRequested) { break; } try { await Task.Delay(interval, token); } catch (TaskCanceledException) { break; } } TaskRunner.Stop(); Client.Handler <ICoreClient>() .CloseSession("Streaming stopped."); } }
public void TaskRunner_Can_Start_Then_Cancel_And_Dispose_New_TaskRunner() { _taskRunner = new TaskRunner() { OnExecute = RunningAction, OnError = HandleException }; Assert.IsNotNull(_taskRunner); Assert.AreEqual(1000, _taskRunner.Interval); _taskRunner.Start(); _taskRunner.Stop(); Assert.IsFalse(_taskRunner.IsRunning); }
public void TaskRunnerTest() { var taskMock = new TaskMock(); var timerMock = MockRepository.GenerateMock <Timer>(); timerMock.Expect(m => m.Elapsed += (sender, e) => taskMock.Execute()); var timerFactoryMock = MockRepository.GenerateMock <TimerFactory>(); timerFactoryMock.Expect(m => m.CreateTimer()).Return(timerMock); var containerMock = MockRepository.GenerateMock <IUnityContainer>(); containerMock.Expect(m => m.Resolve(typeof(TaskMock))).Return(taskMock); timerMock.Replay(); timerFactoryMock.Replay(); containerMock.Replay(); using (var taskRunner = new TaskRunner(containerMock)) { taskRunner.Start(); Assert.That(taskMock.Executed, Is.False); timerMock.Raise(m => m.Elapsed += null, new object[] { null, null }); Assert.That(taskMock.Executed, Is.True); taskMock.Executed = false; timerMock.Raise(m => m.Elapsed += null, new object[] { null, null }); Assert.That(taskMock.Executed, Is.True); taskRunner.Stop(); } }
public void Start_TimerMustBeDisposedAfterTaskRunWhenOnlyOnceIsFalse() { ITask task = Substitute.For <ITask>(); IDateTimeProvider dateTimeProvider = Substitute.For <IDateTimeProvider>(); DateTime utcNow = new DateTime(2005, 2, 18); TimerStub timer = new TimerStub(utcNow, 1000); timer.Elapsed += (sender, args) => { Assert.IsTrue(timer.Started); }; TaskRunner taskRunner = new TaskRunner(task, 1, dateTimeProvider, timer, false, false, false); taskRunner.Start(); Assert.IsTrue(timer.Started); Stopwatch sw = Stopwatch.StartNew(); const int timeout = 10 * 1000; while (timer.StartCallCount < 2 && sw.ElapsedMilliseconds < timeout) { } sw.Stop(); taskRunner.Stop(); Assert.IsTrue(timer.Stoped); Assert.IsFalse(timer.IsRunning); taskRunner.Dispose(); }
protected virtual void OnStopStreaming(object sender, ProtocolEventArgs <StopStreaming> e) { TaskRunner.Stop(); }
protected virtual void OnClientSocketClosed(object sender, EventArgs e) { TaskRunner.Stop(); }
protected void Application_Stop() { _taskRunner.Stop(); }
protected virtual void OnChannelStreamingStop(object sender, ProtocolEventArgs <ChannelStreamingStop> e) { TaskRunner.Stop(); }
private void OnChannelStreamingStop(object sender, ProtocolEventArgs <ChannelStreamingStop> e) { TaskRunner.Stop(); }
private void OnClientSocketClosed(object sender, EventArgs e) { TaskRunner.Stop(); }