public void Run() { while (true) { string input = Console.ReadLine(); OnProcessed.Invoke(input); } }
/// <summary> /// asynchronously wait for GameEvent to be processed /// </summary> /// <returns>waitable task </returns> public Task <GameEvent> WaitAsync(int timeOut = int.MaxValue) { return(Task.Run(() => { OnProcessed.Wait(timeOut); return this; })); }
private void InvokeProcessed(OnProcessedArgs args) { OnProcessed handler = Processed; if (handler != null) { handler(this, args); } }
private async void btn_Save_Click(object sender, RoutedEventArgs e) { OnProcessing?.Invoke(); await Task.Delay(5000); await _db.SaveChangesAsync(); OnProcessed?.Invoke(_mission, _isNew); }
protected void ProcessOffset(int done, int positions) { var ev = new AlgoProcessedEvent { LinesDone = done, PositionsSet = positions }; OnProcessed?.Invoke(ev); }
public void ProcessMessage(object sender, BasicDeliverEventArgs e) { var mi = MessageInfo(e); try { _logger.LogInformation($@"Got message {mi}"); TSrc src; using (var ms = new MemoryStream(e.Body)) { src = ProtoBuf.Serializer.Deserialize <TSrc>(ms); _logger.LogInformation($@"Message {mi} JSON view: {JsonConvert.SerializeObject(src, Formatting.Indented)}"); } var dst = _transformer.Transform(src); _writer.WriteAsync(dst).Wait(); _channel.BasicAck(e.DeliveryTag, false); OnProcessed?.Invoke(this, new MessageProcessedEventArgs <TSrc>(src)); _logger.LogInformation($"Message processed {mi}"); } catch (Exception ex) { _logger.LogError($@"Error message process {mi} Requeue after {_rabbitConfig.RequeueOnErrorAfter} Error {ex.Message}. {ex}"); OnProcessError?.Invoke(this, new MessageProcessErrorEventArgs(ex)); Task.Run(async() => { await Task.Delay(_rabbitConfig.RequeueOnErrorAfter); _channel?.BasicNack(e.DeliveryTag, false, true); _logger.LogInformation($@"Reqeue message {mi}"); }); } }
/// <summary> /// 引发路由器处理消息完毕时的事件 /// </summary> /// <param name="sender">触发事件的路由器</param> /// <param name="e">参数包装</param> public void RaiseProcessedEvent(IRouteable sender, EventArgs e) { OnProcessed?.Invoke(sender, e); }