SystemTrayMenu/Utilities/AppRestart.cs
Markus Hofknecht d1b8c0b279 #88, #69, #103, #104, #105, #97, #106 ,version 0.10.2.8
[Feature] Code Analyze and Refactor 0.11 (#88)
[Feature] Mouse disturbing while using keys (#69)
[Feature] Reload menu when reenter or click (#103)
[BUG] Crash when fast mouse movings (#104)
[BUG] Loading was shown too often (#105)
[BUG] submenu wrong location in edgecase (#97)
[BUG] Folder shown as open (green) but is not open (#106)
2020-06-20 17:38:21 +02:00

58 lines
1.4 KiB
C#

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace SystemTrayMenu.Utilities
{
internal class AppRestart
{
public static event EventHandlerEmpty BeforeRestarting;
private static void Restart(string reason)
{
BeforeRestarting?.Invoke();
Log.Info($"Restart by '{reason}'");
Log.Close();
using (Process p = new Process())
{
p.StartInfo = new ProcessStartInfo(
Process.GetCurrentProcess().
MainModule.FileName);
p.Start();
};
Application.Exit();
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static string GetCurrentMethod()
{
StackTrace st = new StackTrace();
StackFrame sf = st.GetFrame(1);
return sf.GetMethod().Name;
}
internal static void ByThreadException()
{
Restart(GetCurrentMethod());
}
internal static void ByMenuNotifyIcon()
{
Restart(GetCurrentMethod());
}
internal static void ByDisplaySettings(object sender, EventArgs e)
{
Restart(GetCurrentMethod());
}
internal static void ByConfigChange()
{
Restart(GetCurrentMethod());
}
}
}