diff --git a/Apewer.Windows/WinForm/Tray.cs b/Apewer.Windows/WinForm/Tray.cs
index 4a303af..436e3fd 100644
--- a/Apewer.Windows/WinForm/Tray.cs
+++ b/Apewer.Windows/WinForm/Tray.cs
@@ -311,16 +311,22 @@ namespace Apewer.WinForm
#region run
+ /// 唯一实例。
+ public static Tray Instance { get; private set; }
+
/// 已启动的服务名称。
public static string ServiceName { get; private set; }
- /// 在当前线程运行托盘程序,并启动消息循环。
- /// 启动托盘后执行的程序。
+ /// 在当前线程运行托盘程序,并启动消息循环。此方法应在主线程中调用,并且此方法将阻塞当前线程。
+ /// 托盘启动后,将在后台线程执行参数中指定的程序。
+ /// (在后台线程执行)启动托盘后执行的程序。
///
+ ///
[STAThread]
public static void Run(Action action)
{
if (action == null) throw new ArgumentNullException(nameof(action));
+ if (Instance != null) throw new InvalidOperationException($"已存在实例,无法再次启动。");
Control.CheckForIllegalCrossThreadCalls = false;
Application.EnableVisualStyles();
@@ -337,14 +343,14 @@ namespace Apewer.WinForm
}
}
- var instance = new Tray(action);
+ Instance = new Tray(action);
// action.Invoke(instance);
Application.Run();
}
/// 启动服务。
- /// 服务启动后执行的程序。
- /// 停止服务时执行的程序。
+ /// (在后台线程执行)服务启动后执行的程序。
+ /// (同步执行)停止服务时执行的程序。
public static void Service(Action onStart, Action onStop = null)
{
var processName = Process.GetCurrentProcess().ProcessName;