From 71359a43282acd6e3ddc70ee6918e025d9526348 Mon Sep 17 00:00:00 2001 From: ww-rm Date: Sun, 21 Sep 2025 00:01:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=A4=9A=E9=80=89=E6=89=93?= =?UTF-8?q?=E5=BC=80=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- SpineViewer/App.xaml.cs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/SpineViewer/App.xaml.cs b/SpineViewer/App.xaml.cs index 62672fc..c0a342f 100644 --- a/SpineViewer/App.xaml.cs +++ b/SpineViewer/App.xaml.cs @@ -18,6 +18,8 @@ namespace SpineViewer /// public partial class App : Application { + public const string ProgId = "SpineViewer.skel"; + public static readonly string ExeFilePath = Environment.ProcessPath; public static readonly string ProcessName = Process.GetCurrentProcess().ProcessName; public static readonly string Version = Assembly.GetExecutingAssembly().GetCustomAttribute()?.InformationalVersion; @@ -123,7 +125,7 @@ namespace SpineViewer // 已有实例在运行,把参数通过命名管道发过去 using (var client = new NamedPipeClientStream(".", PipeName, PipeDirection.Out)) { - client.Connect(1000); // 等待 1 秒 + client.Connect(10000); // 10 秒超时 using (var writer = new StreamWriter(client)) { foreach (var v in args) @@ -144,6 +146,16 @@ namespace SpineViewer { var t = new Task(() => { + while (Current is null) Thread.Sleep(10); + while (true) + { + var windowCreated = false; + Current.Dispatcher.Invoke(() => windowCreated = Current.MainWindow is MainWindow); + if (windowCreated) + break; + else + Thread.Sleep(100); + } while (true) { using (var server = new NamedPipeServerStream(PipeName, PipeDirection.In)) @@ -158,11 +170,7 @@ namespace SpineViewer if (args.Count > 0) { - Current.Dispatcher.Invoke(() => - { - if (Current?.MainWindow is MainWindow mainWindow) - mainWindow.OpenFiles(args); - }); + Current.Dispatcher.Invoke(() => ((MainWindow)Current.MainWindow).OpenFiles(args)); } } }