Windows services opens a win application form.

  • Thread starter Thread starter Andrew
  • Start date Start date
A

Andrew

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
 
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.
 
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

Family Tree Mike said:
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.



Andrew said:
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
 
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.");
}


Andrew said:
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

Family Tree Mike said:
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.



Andrew said:
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
 
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/
 
Back
Top