37 lines
1.2 KiB
C#
37 lines
1.2 KiB
C#
using System;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
internal static class Program
|
|
{
|
|
[STAThread]
|
|
private static void Main(string[] args)
|
|
{
|
|
bool startInTray = Array.Exists(args, arg =>
|
|
String.Equals(arg, StartupRegistration.BackgroundArgument, StringComparison.OrdinalIgnoreCase));
|
|
Application.EnableVisualStyles();
|
|
Application.SetCompatibleTextRenderingDefault(false);
|
|
|
|
bool firstInstance;
|
|
using (Mutex instance = new Mutex(true, "Local\\DailyFileSync-6DF99A2D", out firstInstance))
|
|
{
|
|
if (!firstInstance)
|
|
{
|
|
if (!startInTray)
|
|
MessageBox.Show("文件同步工具已在运行,可从任务栏通知区域打开。", "每日文件同步",
|
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
return;
|
|
}
|
|
|
|
using (MainForm form = new MainForm())
|
|
using (ApplicationContext loop = new ApplicationContext())
|
|
{
|
|
form.FormClosed += (sender, eventArgs) => loop.ExitThread();
|
|
form.Start(startInTray);
|
|
Application.Run(loop);
|
|
}
|
|
instance.ReleaseMutex();
|
|
}
|
|
}
|
|
}
|