Avoid Sharing Violations in logs

This commit is contained in:
alzeih
2010-06-18 16:05:50 +12:00
parent 5922a6c446
commit 2da06d3744

View File

@@ -47,9 +47,20 @@ namespace OpenRA
public static void AddChannel(string channelName, string filename, bool upload, bool diff)
{
StreamWriter writer = File.CreateText(LogPathPrefix + filename);
writer.AutoFlush = true;
if (channels.ContainsKey(channelName)) return;
/* HACK: avoid sharing violations if running multiple instances */
StreamWriter writer = null;
while (writer == null)
{
try
{
writer = File.CreateText(LogPathPrefix + filename);
}
catch(IOException e){ filename = new Random().Next().ToString() + filename; }
}
writer.AutoFlush = true;
channels.Add(channelName, new ChannelInfo() { Upload = upload, Filename = filename, Writer = writer, Diff = diff });
}