Groups | Blog | Home
all groups > dotnet framework > april 2008 >

dotnet framework : Windows services opens a win application form.


Eugene Mayevski
4/24/2008 12:00:00 AM
Hello!
You wrote on Thu, 24 Apr 2008 06:51:05 -0700:

A> How do I get my Windows service opens form in windows application ?

Services must not have UI. This was a bad practice long before Vista, in
Vista this is simply forbidden (technically). You must create a separate UI
application and use it to show any information from the service.

With best regards,
Eugene Mayevski
http://mayevski.blogspot.com/
Andrew
4/24/2008 6:51:05 AM
Windows services opens a win application form.

Hi,
How do I get my Windows service opens form in windows application ?

I have this bit of code :

Service1.cs
===========
using System.Windows.Forms;

protected override void OnStart(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form2());
eventLog1.WriteEntry("Start DONE.");
}
This does not work. When I start my service it just times out.
Any ideas ?

cheers.
Andrew
Family Tree Mike
4/24/2008 8:37:01 AM
You should not have a user interface from within a service. The service
typically runs with no desktop on which to display the interface. If
neccessary you will want an external application run by the user to
communicate with the service.

That said, on XP, you may enable desktop interaction as a setting on the
service.



[quoted text, click to view]
Andrew
4/24/2008 9:51:07 AM
Thanks.
I've enabled that, but when I attempt to Start the service, the progress bar
just goes slowly and never reaches the end til I get an error message about
Timing out.

Windows is attempting to start the following service on Local Computer
MyNewService4.

I've tried adding :

Thread.Sleep(1000);

However, I never see Form2. Any suggestions ?

cheers
Andrew

[quoted text, click to view]
Family Tree Mike
4/24/2008 10:07:03 AM
Sorry, I had not viewed your actual code. You should not be opening the form
as if you are starting a new application, but rather create an instance and
show it.

protected override void OnStart(string[] args)
{
// Application.EnableVisualStyles();
// Application.SetCompatibleTextRenderingDefault(false);
// Application.Run(new Form2());
Form2 f2 = new Form2();
f2.show();
eventLog1.WriteEntry("Start DONE.");
}


[quoted text, click to view]
AddThis Social Bookmark Button