Hi Benzi,
Thanks for your information.
Yes, by creating a VS.net2003 Windows Service project with your code
snippet, I can reproduce the problem. Further research shows that the
problem lies in Process.ProcessName property.
Below is some additional interesting test result:
1. In my 1G RAM machine, I tried to remove the string s =
Process.GetCurrentProcess().ProcessName code into the OnStop() method, I
find that the "stop" command will also experience the timeout problem.
2. On my another 2G RAM machine, I find that when the code is executed in
OnStop method, "stop" command will work well, however, it will still
experience the timeout if I execute the code in main method.
These tests show that my 2G RAM machine has a better hardware performance,
so OnStop method will return timely. However, in OnStart method, since the
OnStart wait period is very short, both 2 machines will fail to return
timely. So it makes sense.
Then I used the VS.net2003 debugger to attach the Windows Service process
while it is hang. By breaking the process while hang several times, I
always got the following managed call stack:
system.dll!System.Diagnostics.PerformanceMonitor.GetData(string item)
Line 1192 + 0xf4 bytes C#
system.dll!System.Diagnostics.PerformanceCounterLib.GetPerformanceData(strin
g item) Line 956 + 0xa8 bytes C#
system.dll!System.Diagnostics.PerformanceCounterLib.get_CategoryTable()
Line 114 + 0x56 bytes C#
system.dll!System.Diagnostics.PerformanceCounterLib.GetPerformanceData(strin
g[] categories, int[] categoryIndexes) Line 941 + 0x3e bytes C#
system.dll!System.Diagnostics.NtProcessManager.GetProcessInfos(System.Diagno
stics.PerformanceCounterLib library) Line 2664 + 0xa3 bytes C#
system.dll!System.Diagnostics.NtProcessManager.GetProcessInfos(string
machineName, bool isRemoteMachine) Line 2636 + 0xa4 bytes C#
system.dll!System.Diagnostics.ProcessManager.GetProcessInfos(string
machineName) Line 2243 + 0x29 bytes C#
system.dll!System.Diagnostics.Process.EnsureState(System.Diagnostics.Process
.State state) Line 1092 + 0x116 bytes C#
system.dll!System.Diagnostics.Process.get_ProcessName() Line 657 + 0x11
bytes C#
dummyservice.exe!DummyService.Service1.Main() Line 33 + 0x12 bytes C#
So, it seems that the .Net1.1 Process.ProcessName property internally uses
PerformanceCounterLib to query the process/thread information. And there is
certain loop calling in the implementation which causes the long
time-consuming.
Then I tried to understand why the .Net2.0 did not experience the hang
timeout issue. In Reflector, it reveals that .Net2.0 changed the
Process.get_ProcessName implementation, which will not use
PerformanceCounterLib internally to query the process/thread information. I
assume that our CLR team has awared of the ProcessName property performance
problem in .Net1.1, so they changed the implementation in .Net2.0.
To workaround this problem, you upgrade your project to the .Net2.0, which
will make the problem go away. Does it meet your need? If you still want to
go with .Net1.1, I think you have to change your implementation to use
Mutex approach.
Hope this helps.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.