private async Task ConnectedCallback(UvConnectRequest connect, int status, UvException error, TaskCompletionSource <int> tcs) { connect.Dispose(); if (error != null) { tcs.SetException(error); return; } var writeReq = new UvWriteReq(Log); try { DispatchPipe.ReadStart( (handle, status2, state) => ((UvListenerSecondary)state)._buf, (handle, status2, state) => ((UvListenerSecondary)state).ReadStartCallback(handle, status2), this); writeReq.Init(_thread); var result = await writeReq.WriteAsync( DispatchPipe, new ArraySegment <ArraySegment <byte> >(new[] { new ArraySegment <byte>(_pipeMessage) })); if (result.Error != null) { tcs.SetException(result.Error); } else { tcs.SetResult(0); } } catch (Exception ex) { DispatchPipe.Dispose(); tcs.SetException(ex); } finally { writeReq.Dispose(); } }
private void StartedCallback(TaskCompletionSource <int> tcs) { var connect = new UvConnectRequest(Log); try { DispatchPipe.Init(_thread.Loop, _thread.QueueCloseHandle, true); connect.Init(_thread); connect.Connect( DispatchPipe, _pipeName, (connect2, status, error, state) => ConnectCallback(connect2, status, error, (TaskCompletionSource <int>)state), tcs); } catch (Exception ex) { DispatchPipe.Dispose(); connect.Dispose(); tcs.SetException(ex); } }