diff --git a/BizHawk.Client.Common/BizHawk.Client.Common.csproj b/BizHawk.Client.Common/BizHawk.Client.Common.csproj
index c0b0e2935c..6ca260c29c 100644
--- a/BizHawk.Client.Common/BizHawk.Client.Common.csproj
+++ b/BizHawk.Client.Common/BizHawk.Client.Common.csproj
@@ -228,6 +228,7 @@
+
diff --git a/BizHawk.Client.Common/TempFileCleaner.cs b/BizHawk.Client.Common/TempFileCleaner.cs
new file mode 100644
index 0000000000..b6a7f0eda6
--- /dev/null
+++ b/BizHawk.Client.Common/TempFileCleaner.cs
@@ -0,0 +1,61 @@
+using System;
+using System.IO;
+
+namespace BizHawk.Client.Common
+{
+ ///
+ /// Starts a thread which cleans any filenames in %temp% beginning with bizhawk.bizdelete.
+ /// Files shouldn't be named that unless they're safe to delete, but notably, they may stil be in use. That won't hurt this component.
+ /// When they're no longer in use, this component will then be able to delete them.
+ ///
+ public static class TempFileCleaner
+ {
+ //todo - manage paths other than %temp%, make not static, or allow adding multiple paths to static instance
+
+ public static void Start()
+ {
+ lock (typeof(TempFileCleaner))
+ {
+ if (thread != null)
+ return;
+
+ thread = new System.Threading.Thread(ThreadProc);
+ thread.IsBackground = true;
+ thread.Priority = System.Threading.ThreadPriority.Lowest;
+ thread.Start();
+ }
+ }
+
+ static void ThreadProc()
+ {
+ var di = new DirectoryInfo(Path.GetTempPath());
+ for (; ; )
+ {
+ var fis = di.GetFiles("bizhawk.bizdelete*");
+ foreach (var fi in fis)
+ {
+ try
+ {
+ fi.Delete();
+ }
+ catch
+ {
+ }
+
+ //try not to do more than one thing per frame
+ System.Threading.Thread.Sleep(100);
+ }
+
+ //try not to slam the filesystem too hard, we dont want this to cause any hiccups
+ System.Threading.Thread.Sleep(5000);
+ }
+ }
+
+ public static void Stop()
+ {
+ }
+
+ static System.Threading.Thread thread;
+ }
+
+}
\ No newline at end of file
diff --git a/BizHawk.Client.EmuHawk/Program.cs b/BizHawk.Client.EmuHawk/Program.cs
index 8267396640..794f97fac4 100644
--- a/BizHawk.Client.EmuHawk/Program.cs
+++ b/BizHawk.Client.EmuHawk/Program.cs
@@ -59,6 +59,7 @@ namespace BizHawk.Client.EmuHawk
}
}
+ BizHawk.Client.Common.TempFileCleaner.Start();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
string iniPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "config.ini");