Windows Service that interacts with desktop

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am writing a service that I want to be able to display "debug" information on a desktop window. I have the following code that displays the form (when service is properly set up) and the service starts. However the form is not drawing itself completely and it is non responsive ("Not Responding" in the caption) and thus I can not see any information printed on it! I can stop the service and then the form is removed. Does anyone know why the form won't not respond?

Public Class FGDataService
Inherits System.ServiceProcess.ServiceBase

[Component Designer generated code]

Dim panel As InfoPanel
Protected Overrides Sub OnStart(ByVal args() As String)
'if the service can interact with desktop, then display log window
panel = New InfoPanel
panel.Visible = True
panel.txtInfo.Text += "Service Started"
End Sub
End Class
 
The OnStart method is called on a thread pool thread. When that thread
completes the OnStart routine it returns to the ThreadPool code where it
waits on a synchronization object for more work to perform. So the thread
that creates the window never processes the messages in the window's message
queue. The thread that calls the OnStart routine should never do any work
other than some, small amount of initialization and setting up other threads
(either user created or threadpool threads) to perform the service's real
work.

If you wish to show a form on the interactive desktop (I assume this is for
debugging only, it really shouldn't be used for production code) you should
create a new thread and create the form object and call its ShowDialog
method on that thread so that the UI will have a dedicated thread. When
other threads in the service need to print messages on the UI then use
Control.Invoke (or BeginInvoke) on the form object to marshal the call to
the correct thread.


RaggiHolm said:
I am writing a service that I want to be able to display "debug"
information on a desktop window. I have the following code that displays
the form (when service is properly set up) and the service starts. However
the form is not drawing itself completely and it is non responsive ("Not
Responding" in the caption) and thus I can not see any information printed
on it! I can stop the service and then the form is removed. Does anyone
know why the form won't not respond?
Public Class FGDataService
Inherits System.ServiceProcess.ServiceBase

[Component Designer generated code]

Dim panel As InfoPanel
Protected Overrides Sub OnStart(ByVal args() As String)
'if the service can interact with desktop, then display log window
panel = New InfoPanel
panel.Visible = True
panel.txtInfo.Text += "Service Started"
End Sub
End Class
 
Hi
I want a solution from you rather that giving solution to ur question.

"I want a Windows Service which should run as a part of the OS before any
user logs in to the machine and it will open a port and constantly listen
from that port. If any data come to that port then the service should
display a dialog containing the data received from the port. Can it be
possible ??? If yes then how can i achieve this ???

Thanx


Stephen Martin said:
The OnStart method is called on a thread pool thread. When that thread
completes the OnStart routine it returns to the ThreadPool code where it
waits on a synchronization object for more work to perform. So the thread
that creates the window never processes the messages in the window's message
queue. The thread that calls the OnStart routine should never do any work
other than some, small amount of initialization and setting up other threads
(either user created or threadpool threads) to perform the service's real
work.

If you wish to show a form on the interactive desktop (I assume this is for
debugging only, it really shouldn't be used for production code) you should
create a new thread and create the form object and call its ShowDialog
method on that thread so that the UI will have a dedicated thread. When
other threads in the service need to print messages on the UI then use
Control.Invoke (or BeginInvoke) on the form object to marshal the call to
the correct thread.


RaggiHolm said:
I am writing a service that I want to be able to display "debug"
information on a desktop window. I have the following code that displays
the form (when service is properly set up) and the service starts. However
the form is not drawing itself completely and it is non responsive ("Not
Responding" in the caption) and thus I can not see any information printed
on it! I can stop the service and then the form is removed. Does anyone
know why the form won't not respond?
Public Class FGDataService
Inherits System.ServiceProcess.ServiceBase

[Component Designer generated code]

Dim panel As InfoPanel
Protected Overrides Sub OnStart(ByVal args() As String)
'if the service can interact with desktop, then display log window
panel = New InfoPanel
panel.Visible = True
panel.txtInfo.Text += "Service Started"
End Sub
End Class
 
Back
Top