Пример #1
0
 private void RunHandlerTask(IConnectionHandler handler, HandlerContext context)
 {
     var handlerTask = Task.Run(async () =>
     {
         if (handler is IAsyncConnectionHandler)
         {
             await ((IAsyncConnectionHandler)handler).ProcessAsync(context);
         }
         else
         {
             await Task.Run(() => handler.Process(context));
         }
     }).ContinueWith(t =>
     {
         if (t.IsFaulted)
         {
             OnHandlerTaskError(handler, context);
         }
     });
     activeHandlerTasks.Add(handlerTask);
 }
Пример #2
0
 private IConnectionHandler CreateHandler(HandlerContext context)
 {
     return handlerFactory.Invoke(context);
 }
Пример #3
0
 private void OnHandlerTaskError(IConnectionHandler handler, HandlerContext context)
 {
 }
Пример #4
0
 private Task RunListenerTask()
 {
     return Task.Run(async () =>
     {
         while (!cancellationSource.IsCancellationRequested)
         {
             var socket = await tcpListener.AcceptSocketAsync();
             var context = new HandlerContext(new TcpChannel(socket));
             var handler = CreateHandler(context);
             RunHandlerTask(handler, context);
         }
     }).ContinueWith(OnListenerTaskError);
 }