public void Start(ISourceBlock sourceBlock) { if (m_Disposed) { throw new ObjectDisposedException(null, "DataflowNetwork already disposed."); } try { //Begin processing the soruce StartProcessingSource(sourceBlock); // Block and wait for all the dataflow-network constituents to complete their work. var waitForTasks = PendingTasks.ToArray(); if (waitForTasks.Length > 0) { Task.WaitAll(waitForTasks.ToArray(), Cts.Token); } LogAgent.LogInfo(DataflowNetworkConstituent.Network, Name, "Network finished successfully."); OutputStatistics(); LogAgent.Complete(); } catch (AggregateException ex) { LogAgent.LogError(DataflowNetworkConstituent.Network, Name, ex.Flatten(), "The network encountered an unhandled exception."); throw new DataflowNetworkFailedException("The datanetwork " + Name + " failed. See the inner exception for more details", ex); } catch (OperationCanceledException) { var exceptions = PendingTasks.Where(task => task.IsFaulted).Select(task => task.Exception); foreach (var ex in exceptions) { LogAgent.LogError(DataflowNetworkConstituent.Network, Name, ex.Flatten(), "The network encountered an unhandled exception."); } } catch (Exception ex) { LogAgent.LogError(DataflowNetworkConstituent.Network, Name, ex, "The network encountered an unhandled exception."); throw new DataflowNetworkFailedException("The datanetwork " + Name + " failed. See the inner exception for more details", ex); } finally { DisposePendingTasks(); Dispose(); } }
public void LogStatistics() { string stats = StatisticsHelper.FormatLogMessage(Name, "", Interlocked.Read(ref m_NumMessagesProcessed), Interlocked.Read(ref m_NumBrokenMsgs)); LogAgent.LogInfo(TaskType, Name, stats); }