无法在Windows服务中使用NDde.dll

C#代码:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.IO; using System.Linq; using System.ServiceProcess; using System.Text; using System.Threading.Tasks; using NDde.Client; namespace Test { public partial class Service1 : ServiceBase { System.Timers.Timer timeDelay; int count; public Service1() { InitializeComponent(); timeDelay = new System.Timers.Timer(); timeDelay.Elapsed += new System.Timers.ElapsedEventHandler(WorkProcess); } public void WorkProcess(object sender, System.Timers.ElapsedEventArgs e) { string process = "Timer Tick " + count; LogService(process); count++; } protected override void OnStart(string[] args) { LogService("Service is Started"); timeDelay.Enabled = true; } protected override void OnStop() { LogService("Service Stoped"); timeDelay.Enabled = false; } private void LogService(string content) { FileStream fs = new FileStream(@"C:\TestServiceLog.txt", FileMode.OpenOrCreate, FileAccess.Write); StreamWriter sw = new StreamWriter(fs); sw.BaseStream.Seek(0, SeekOrigin.End); sw.WriteLine(content+this.GetFirefoxUrl()); sw.Flush(); sw.Close(); } public string GetFirefoxUrl() { DdeClient dde = new DdeClient("Firefox", "WWW_GetWindowInfo"); dde.Connect(); string url = dde.Request("URL", int.MaxValue); dde.Disconnect(); return url; } } } 

嗨,我写了上面的代码,但我无法执行任务GetFirefoxUrl()。 它给我以下错误。 我该如何解决这个问题?

服务无法启动。 NDde.DdeException:客户端无法连接到“Firefox | WWW_GetWindowInfo”。 确保服务器应用程序正在运行,并且它支持指定的服务名称和主题名称对。 —> NDde.Foundation.DdemlException:客户端无法连接到“Firefox | WWW_GetWindowInfo”。 确保服务器应用程序正在运行,并且它支持指定的服务名称和主题名称对。 在System.Windows.Forms.Control.MarshaledInvoke(控制调用者,委托方法,对象[] args,布尔同步)在System.Windows.Forms.Control.Invoke(委托方法,对象[]参数)在NDde.Advanced.DdeContext .DdeThread.Invoke(Delegate方法,Object [] args)在NDde.Client.DdeClient.Connect()—内部exception堆栈跟踪结束—在NDde.Client.DdeClient.Connect()在Test.Service1。在System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)处的Test.Service1.OnStart(String [] args)上的Test.Service1.LogService(String content)上的GetFirefoxUrl()

我已经检查了与此相关的其他线程没有一个给了我一个解决scheme。 我希望有人指导我做到这一点。