简体   繁体   English

如何从 C# 中的 Windows 服务调用 Winform 方法

[英]How to call Winform method from Windows service in C#

I want to call Winform method from Windows Service.我想从 Windows 服务调用 Winform 方法。

For Example, Here is my Winform application code (MyWinForm),例如,这是我的 Winform 应用程序代码(MyWinForm),

public void TestMethod(){
     MessageBox.Show("Hello World!");
}

And here is my Windows Service (MyService),这是我的 Windows 服务(MyService),

protected override void OnStart(string[] args){
     MyWinform myWinform = new MyWinform();
     myWinform.TestMethod();
}

Please let me know if there is any other way to do this.请让我知道是否有其他方法可以做到这一点。 Thank you.谢谢你。

You can access winform methods from windows service by using name space System.Windows.Forms How ever as hayden said you can not access UI from windows servcie application You can access winform methods from windows service by using name space System.Windows.Forms How ever as hayden said you can not access UI from windows servcie application

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM