diff --git a/StarAgent/StarAgent.csproj b/StarAgent/StarAgent.csproj
index 3a5ee631..d3218555 100644
--- a/StarAgent/StarAgent.csproj
+++ b/StarAgent/StarAgent.csproj
@@ -36,6 +36,11 @@
+
+
+
+
+
@@ -49,4 +54,8 @@
+
+
+
+
diff --git a/Stardust/Managers/ServiceController.cs b/Stardust/Managers/ServiceController.cs
index e1cb5e77..f2766aad 100644
--- a/Stardust/Managers/ServiceController.cs
+++ b/Stardust/Managers/ServiceController.cs
@@ -1,5 +1,6 @@
using System.Diagnostics;
using NewLife;
+using NewLife.Agent.Windows;
using NewLife.Log;
using NewLife.Remoting.Clients;
using NewLife.Threading;
@@ -393,7 +394,19 @@ public Boolean Start()
if (!si.UserName.IsNullOrEmpty())
WriteLog("启动用户:{0}", si.UserName);
- var p = Process.Start(si);
+ Process? p = null;
+
+ // Windows桌面用户运行
+ if (Runtime.Windows && service.UserName == "$")
+ {
+ var desktop = new Desktop { Log = Log };
+ var pid = desktop.StartProcess(si.FileName, si.Arguments, si.WorkingDirectory);
+ p = Process.GetProcessById((Int32)pid);
+ }
+ else
+ {
+ p = Process.Start(si);
+ }
if (StartWait > 0 && p != null && p.WaitForExit(StartWait) && p.ExitCode != 0)
{
WriteLog("启动失败!ExitCode={0}", p.ExitCode);
@@ -605,20 +618,24 @@ public Boolean Check()
// 检查内存限制
if (inf.MaxMemory <= 0) return p;
+ var mem = p.WorkingSet64 / 1024 / 1024;
+ span?.AppendTag($"MaxMemory={inf.MaxMemory}M WorkingSet64={mem}M");
+
// 定期清理内存
- if (Runtime.Windows && _nextCollect < DateTime.Now)
+ if (Runtime.Windows && _nextCollect < DateTime.Now && mem > inf.MaxMemory)
{
_nextCollect = DateTime.Now.AddSeconds(600);
try
{
- NativeMethods.EmptyWorkingSet(p.Handle);
+ Runtime.FreeMemory(p.Id);
+ //NativeMethods.EmptyWorkingSet(p.Handle);
}
catch { }
- }
- var mem = p.WorkingSet64 / 1024 / 1024;
- span?.AppendTag($"MaxMemory={inf.MaxMemory}M WorkingSet64={mem}M");
+ p.Refresh();
+ mem = p.WorkingSet64 / 1024 / 1024;
+ }
if (mem <= inf.MaxMemory) return p;
WriteLog("内存超限!{0}>{1}", mem, inf.MaxMemory);
diff --git a/Stardust/Managers/ServiceManager.cs b/Stardust/Managers/ServiceManager.cs
index 6d4ec2cc..0c54260e 100644
--- a/Stardust/Managers/ServiceManager.cs
+++ b/Stardust/Managers/ServiceManager.cs
@@ -1,4 +1,5 @@
-using NewLife;
+using System.Net.Http;
+using NewLife;
using NewLife.Http;
using NewLife.IO;
using NewLife.Log;
diff --git a/Stardust/Stardust.csproj b/Stardust/Stardust.csproj
index 45098f1b..8ee56e6c 100644
--- a/Stardust/Stardust.csproj
+++ b/Stardust/Stardust.csproj
@@ -72,6 +72,8 @@
+
+