windows service and the Responding property of a Process

G

Guest

I have a simple snippet of code that loops through a process() and writes to
the eventlog the contents of the Responding property. I have run this in a
console app and it returns False as it should. I have moved this code to a
windows service but it will always return true. The code is:

Dim proc() As Process = Process.GetProcessesByName(_processToMonitor)
Dim p As Process
For Each p In proc
EventLog.WriteEntry(p.ProcessName & _
" id: " & p.Id & _
" full path: " & p.Modules(0).FileName & _
" responding?:" & p.Responding.ToString)
Next

I have tried to change the Account used for the service but always get the
same results (True). I have moved this code to an .exe but I am curious to
why it runs differently in a windows service.

Regards,
David

P.S. If someone wants to test this I have found the easiest why to get an
application to a Not Responding status is to open a large file with notepad.
 
W

Willy Denoyette [MVP]

harumscarum said:
I have a simple snippet of code that loops through a process() and writes
to
the eventlog the contents of the Responding property. I have run this in a
console app and it returns False as it should. I have moved this code to a
windows service but it will always return true. The code is:

Dim proc() As Process =
Process.GetProcessesByName(_processToMonitor)
Dim p As Process
For Each p In proc
EventLog.WriteEntry(p.ProcessName & _
" id: " & p.Id & _
" full path: " & p.Modules(0).FileName & _
" responding?:" & p.Responding.ToString)
Next

I have tried to change the Account used for the service but always get the
same results (True). I have moved this code to an .exe but I am curious to
why it runs differently in a windows service.

Regards,
David

P.S. If someone wants to test this I have found the easiest why to get an
application to a Not Responding status is to open a large file with
notepad.

This is because Windows services run in a sandboxed desktop/windowstation,
that means it has no access to the interactive desktop/windowsstation.

To run your service in the interactive desktop, you have to enable the
"Interact with desktop" attribute for your service, but this is not a good
idea and should only be done when debugging.

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top