Skip to content

Added DomainUnloaded event. #102

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions src/coverlet.core/CoverageTracker.cs
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ static CoverageTracker()
_markers = new Dictionary<string, List<string>>();
_markerFileCount = new Dictionary<string, int>();
AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
AppDomain.CurrentDomain.DomainUnload += new EventHandler(CurrentDomain_ProcessExit);
}

[ExcludeFromCoverage]
@@ -48,17 +49,22 @@ public static void MarkExecuted(string path, string marker)
[ExcludeFromCoverage]
public static void CurrentDomain_ProcessExit(object sender, EventArgs e)
{
foreach (var kvp in _markers)
lock (_markers)
{
using (var fs = new FileStream($"{kvp.Key}_compressed_{_markerFileCount[kvp.Key]}", FileMode.OpenOrCreate))
using (var gz = new GZipStream(fs, CompressionMode.Compress))
using (var sw = new StreamWriter(gz))
foreach (var kvp in _markers)
{
foreach(var line in kvp.Value)
using (var fs = new FileStream($"{kvp.Key}_compressed_{_markerFileCount[kvp.Key]}", FileMode.OpenOrCreate))
using (var gz = new GZipStream(fs, CompressionMode.Compress))
using (var sw = new StreamWriter(gz))
{
sw.WriteLine(line);
foreach(var line in kvp.Value)
{
sw.WriteLine(line);
}
}
}

_markers.Clear();
}
}
}