From 3f62d18e4361cd1d7a49c126765d95b2ad9c8246 Mon Sep 17 00:00:00 2001
From: chr <chr@mailcom>
Date: 星期二, 04 三月 2025 08:42:07 +0800
Subject: [PATCH] 优化插件;

---
 SolidWorksListener/Listener.cs |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/SolidWorksListener/Listener.cs b/SolidWorksListener/Listener.cs
index 1719930..531f88a 100644
--- a/SolidWorksListener/Listener.cs
+++ b/SolidWorksListener/Listener.cs
@@ -6,6 +6,7 @@
 using System.Net;
 using System.Reflection;
 using System.Runtime.InteropServices;
+using System.Security.Principal;
 using System.Text;
 using System.Timers;
 using System.Windows;
@@ -84,7 +85,7 @@
             // WinAPI_Interop.ShowServiceMessage(msg, "鎻愮ず");
             // ShowMessageBox(msg, "鎻愮ず");
             string exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
-            string alertPath = Path.GetFullPath(Path.Combine(exeDir,"..","Alert.exe"));
+            string alertPath = Path.GetFullPath(Path.Combine(exeDir, "..", "Alert.exe"));
             if (File.Exists(alertPath))
             {
                 Process.Start(alertPath);
@@ -221,9 +222,16 @@
         private bool IsSwRunning()
         {
             Process[] ps = Process.GetProcessesByName("SLDWORKS");
-            bool IsRunning = (ps != null && ps.Length > 0);
+            bool IsRunning = false;
+            if (ps == null || ps.Length <= 0)
+            {
+                log.Debug($"Sw Is Running: {IsRunning}");
+                return false;
+            }
+            IsRunning = true;
+            string username = WindowsIdentity.GetCurrent().Name;
             log.Debug($"Sw Is Running: {IsRunning}");
-            return IsRunning;
+            return false;
         }
 
         /// <summary>
@@ -232,7 +240,7 @@
         private void HandleErr()
         {
             log.Debug($"err_count: {err_count}");
-            if (++err_count > 3)
+            if (++err_count > 5)
             {
                 if (IsSwRunning())
                 {

--
Gitblit v1.9.1