|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
.NET Windows Service OnStart hangs on Process.ProcessNameWe have a C# application running as a Windows Service. Once the service is installed and a start is done on the service, the process will block when accessing information about the current process. The example below placed in the OnStart of a class inheriting from ServiceBase will hang on the proc.ProcessName line. using(System.Diagnostics.Process proc = system.Diagnostics.Process.GetCurrentProcess()) { return proc.ProcessName; // This line will hang long enough to prevent the service from starting for timeout reason. } This hanging issue seems to happen only once in a while. Usually, the first startup of the service will hang and timeout. The second startup will start ok, the third will timeout and so on. Is there a workaround or a fix for this issue? Environment information: OS : WinXP SP1 ..NET: 1.1 SP1 Thanks! Simon Sure, don't run this in OnStart. OnStart is only meant to initialize your
service variables and kick-off a service thread to run the real service code, OnStart must return before the SCM times out, that is withing 30 seconds. So you need to run this on a separate thread. Willy. Show quote "Simon Luckenuik" <simon.luckenuik@newsgroups.nospam> wrote in message news:53DE1FA6-FDCD-4F5E-A712-FA248BE5CC14@microsoft.com... | Hi, | We have a C# application running as a Windows Service. Once the service is | installed and a start is done on the service, the process will block when | accessing information about the current process. The example below placed in | the OnStart of a class inheriting from ServiceBase will hang on the | proc.ProcessName line. | using(System.Diagnostics.Process proc = | system.Diagnostics.Process.GetCurrentProcess()) | { | return proc.ProcessName; // This line will hang long enough to prevent | the service from starting for timeout reason. | } | | This hanging issue seems to happen only once in a while. Usually, the first | startup of the service will hang and timeout. The second startup will start | ok, the third will timeout and so on. | | Is there a workaround or a fix for this issue? | | Environment information: | OS : WinXP SP1 | .NET: 1.1 SP1 | | Thanks! | Simon Just using System.Reflection.Assembly.GetEntryAssembly().Location gets the
entry assembly location from which you can retrieve the process name. This is only applicable if running from default application domain. Or another solution is to use Environment.GetCommandLineArgs(). It returns an array and the first element in the array contains the file name of the executing program. These 2 solutions are not resource intensive and do work well for my needs. Thanks. -- Show quoteSimon "Willy Denoyette [MVP]" wrote: > Sure, don't run this in OnStart. OnStart is only meant to initialize your > service variables and kick-off a service thread to run the real service > code, OnStart must return before the SCM times out, that is withing 30 > seconds. > So you need to run this on a separate thread. > > Willy. > > "Simon Luckenuik" <simon.luckenuik@newsgroups.nospam> wrote in message > news:53DE1FA6-FDCD-4F5E-A712-FA248BE5CC14@microsoft.com... > | Hi, > | We have a C# application running as a Windows Service. Once the service is > | installed and a start is done on the service, the process will block when > | accessing information about the current process. The example below placed > in > | the OnStart of a class inheriting from ServiceBase will hang on the > | proc.ProcessName line. > | using(System.Diagnostics.Process proc = > | system.Diagnostics.Process.GetCurrentProcess()) > | { > | return proc.ProcessName; // This line will hang long enough to prevent > | the service from starting for timeout reason. > | } > | > | This hanging issue seems to happen only once in a while. Usually, the > first > | startup of the service will hang and timeout. The second startup will > start > | ok, the third will timeout and so on. > | > | Is there a workaround or a fix for this issue? > | > | Environment information: > | OS : WinXP SP1 > | .NET: 1.1 SP1 > | > | Thanks! > | Simon > > > Hi
Thanks for your update! Best regards, Peter Huang Microsoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "AS IS" with no warranties, and confers no rights. |
|||||||||||||||||||||||