简体   繁体   中英

How to call Winform method from Windows service in C#

I want to call Winform method from Windows Service.

For Example, Here is my Winform application code (MyWinForm),

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

And here is my Windows Service (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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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