internal void FlushExecutionLog(MemoryStream listenerStream) { // Because the execution log target is filling its own // buffer in a different thread, we have to copy its current buffer // to our own buffer to have a static blob to send with the notification // TODO: A better way of doing this without copying bytes. // Maybe add a "Pause" operation to the binary logger so it blocks its thread // while we read/send the buffer. listenerStream.WriteTo(m_flushedExecutionLog); if (m_finishedSendingPipResults && !m_sendCancellationSource.IsCancellationRequested && m_flushedExecutionLog.Length > 0) { // A final flush of the execution log may come after all the pip results are sent // In that case, we send the blob individually: m_masterClient.NotifyAsync(new WorkerNotificationArgs() { ExecutionLogBlobSequenceNumber = m_xlgBlobSequenceNumber++, ExecutionLogData = new ArraySegment <byte>(m_flushedExecutionLog.GetBuffer(), 0, (int)m_flushedExecutionLog.Length) }, null, m_sendCancellationSource.Token).Wait(); m_flushedExecutionLog.SetLength(0); } }