Using NDepend, how can we removed Cycle Dependencies generated by the compiler due to Tasks (TPL) from the Dependency Matrix.
If we cannot remove them, then how can we easily differentiate them from important cycle dependencies that need our attention.
Are there any best practices around dealing with compiler generated cycle dependencies?
Edit:
The compiler generated dependency cycle can be observed in the top left of the diagram
Code that generates a Dependency Cycle (Compiles in .Net 4.0)
*logger is a field in my class
private void WriteJsonFileToDiskAsync(string filePath, string json)
{
Task.Factory.StartNew(() => WriteJsonFileToDisk(filePath, json))
.ContinueWith(HandleWriteException);
}
private void WriteJsonFileToDisk(string filePath, string json)
{
Stream fileStream = null;
try
{
fileStream = File.Create(filePath);
using (var writer = new StreamWriter(fileStream))
{
fileStream = null;
writer.Write(json);
}
logger.InfoIfDebuggerIsAttached(string.Format(CultureInfo.InvariantCulture, "Persisted file: {0}", filePath));
}
finally
{
if (fileStream != null)
fileStream.Dispose();
}
}
private static void HandleWriteException(Task task)
{
if (task.IsFaulted)
{
//TODO: Handle Exception
}
}