mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-09-29 16:51:18 +13:00
d1b8c0b279
[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)
57 lines
1.4 KiB
C#
57 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());
|
|
}
|
|
}
|
|
}
|