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" <an*******@discussions.microsoft.com> wrote in message
news:B7**********************************@microsof t.com...
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