5

I have created a windows service application in C# to popup a dialog window at particular intervals. While debugging in Visual studio, it is working well. Then I created an installation setup. But after installing the service is not firing to popup the dialog window. What will be the reason and how can I fix it?

user2147570
  • 51
  • 1
  • 2
  • You shouldn't do this, see http://stackoverflow.com/a/12956489/261050. See other answers to that question for workarounds. – Maarten Apr 29 '13 at 07:02
  • possible duplicate of [show a windows form from a window service](http://stackoverflow.com/questions/12953148/show-a-windows-form-from-a-window-service) – Dennis Apr 29 '13 at 07:03
  • If i face this problem i will do this. Put `Try Catch` and `log` the exception into File. and see., :) – RajeshKdev Apr 29 '13 at 07:06
  • @RJK the logged exception won't discuss session 0 isolation and the non-interactive nature of that session – David Heffernan Apr 29 '13 at 07:24

2 Answers2

3

Services run in session 0 which is isolated from the interactive desktop. You cannot show UI from a service. You need to run a separate desktop process to show the UI and then use IPC to communicate between the service and the desktop process.

If your dialog is simple enough you could possibly use WTSSendMessage.

If you want to run code at regular intervals then you may be better off with a scheduled task rather than a service.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
1

How is your service installed? What windows Version are you on?

If vista/7 does Interactive services Detection show up?

Bottom line is windows services where never designed for user interaction.

There is a way however, but I would recommend using a different way to interact with the user

Setting a windows service to interact with the desktop could pose a security issue.

I posted this link Hope it helps

http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/1c3d4b96-c58b-465a-a964-89926bd455f1/

Driftware
  • 99
  • 8