Windows Service Application
-
Dear All, I have created a very basic and simple windows service application using c# in vs 2005. i have override the "onstart" method and i want that when my service starts a message should appear just to confirm that service starts running. the service starts successfully but no message appears to me. i have tried to write that message to a file but still no file is created. this the code bellow
protected override void OnStart(string[] args)
{
System.Windows.Forms.MessageBox.Show("Service is start...");
}i have googled and used topic in msdn to create window service application. why the message box does not appear when i am starting the service?
-
Dear All, I have created a very basic and simple windows service application using c# in vs 2005. i have override the "onstart" method and i want that when my service starts a message should appear just to confirm that service starts running. the service starts successfully but no message appears to me. i have tried to write that message to a file but still no file is created. this the code bellow
protected override void OnStart(string[] args)
{
System.Windows.Forms.MessageBox.Show("Service is start...");
}i have googled and used topic in msdn to create window service application. why the message box does not appear when i am starting the service?
Services do not show UI. They are logged in as adifferent user and can not display data to a desktop. You can use Trace.Assert(false,"Hello");
Natza Mitzi
-
Services do not show UI. They are logged in as adifferent user and can not display data to a desktop. You can use Trace.Assert(false,"Hello");
Natza Mitzi
-
yeah you are right, but if we enable the option "Allow User to Interact with Desktop". we can show UI to the user. i have enabled this option through code, still i need to restart my computer to get affected. I want this without restarting the system.
Instead you can use a client application that interacts with the service. Using GUI in services is dangerous
Natza Mitzi
-
Instead you can use a client application that interacts with the service. Using GUI in services is dangerous
Natza Mitzi
-
yeah you are right, but if we enable the option "Allow User to Interact with Desktop". we can show UI to the user. i have enabled this option through code, still i need to restart my computer to get affected. I want this without restarting the system.
Member 6059028 wrote:
Allow User to Interact with Desktop
This is VERY bad practice. I believe you can't even do this in Vista.
Cheers, Vıkram.
Carpe Diem.
-
can you please have more detail on client application and the interaction way between client and server application. you mean i should call window forms from my installer class.
This is a suggestion of implementation. The installer should install both service and application. The service should run independently (treated as a server) and the application should run as a client, post requests and run the service to do what it needs to. The connection between the client application can be implemented using .net remoting and the interaction will be transparent. My preferred way is to implement a service and a client application that runs from the system tray using a notify icon. The client application can have the service controller for starting/stopping/pausing/installing/uninstalling the service. I saw some articles around the code project with samples of notify icons, service controllers and .net remoting. I hope this helps
Natza Mitzi
-
Dear All, I have created a very basic and simple windows service application using c# in vs 2005. i have override the "onstart" method and i want that when my service starts a message should appear just to confirm that service starts running. the service starts successfully but no message appears to me. i have tried to write that message to a file but still no file is created. this the code bellow
protected override void OnStart(string[] args)
{
System.Windows.Forms.MessageBox.Show("Service is start...");
}i have googled and used topic in msdn to create window service application. why the message box does not appear when i am starting the service?
You can't display interface components in a Windows service.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001 -
You can't display interface components in a Windows service.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001You can - you shouldn't, but you can. Windows Services have a property "Interact with desktop" that allows a user to do precisely this - it's yet another crappy design decision.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
-
You can - you shouldn't, but you can. Windows Services have a property "Interact with desktop" that allows a user to do precisely this - it's yet another crappy design decision.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
I know, but I was trying to keep it as simple as possible for the guy.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
-----
"...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001