public void HandleReceived(NetworkRequest request) { _ = request ?? throw new ArgumentNullException(nameof(request)); Task.Run(async() => { foreach (var id in request.CancelRequests) { if (calls.TryGetValue(id, out Call call)) { call.CancellationToken.Cancel(); } } if (!string.IsNullOrEmpty(request.ApiFunction)) { var call = new Call(request.Token); calls.TryAdd(request.Token, call); NetworkResponse response; if (Api is IApiServerDefinition2 api2) { response = await api2.HandleMessage2(request, call.CancellationToken.Token); } else { response = await Api.HandleMessage(request); } SubmitResponse?.Invoke(response); } }); }