EDN Admin
Well-known member
<p style="line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" I have an application which starts a Windows service when the user logs out. This works fine as per the basic outline of my code segment below. However,
the problem is that this sometimes leads to a .NET Broadcast message... , error when the user logs out, especially on Windows XP. I presume that this is because there is a conflict between the machine trying to logout and the
service starting timeout i.e. both trying to control things at the same time.
<p style="line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" I have been checking on this again (for example at www.csharp-examples.net/restart-windows-service), and this seems to be the way to start a service. However
to avoid these .NET Broadcast messages, I have since commented out these timeout lines so the service is called, and no waiting to ensure that this it has started. The other way that I can see of doing this is by starting the service earlier i.e. if
it looks like the user is going to log out, but then I have the problem of stopping it if the user doesnt log out.
<p style="line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" My outline code below for starting a service:
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" if (serviceExists)<br/>
{<br/>
if (winService.Status == ServiceControllerStatus.Stopped || winService.Status
== ServiceControllerStatus.Paused)<br/>
{<br/>
TimeSpan timeout = TimeSpan.FromMilliseconds(10000);
//have commented out this line to avoid .NET Broadcast message<br/>
<br/>
winService.Start(args);<br/>
<br/>
winService.WaitForStatus(ServiceControllerStatus.Running,
timeout); //have commented out this line to avoid .NET Broadcast message<br/>
}<br/>
}
<p style="line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" So my questions are as below:
<p style="line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" 1) <span style="font-size:12pt; font-family:"Times New Roman","serif" Is there a need to allow this wait for the service to start for
10 seconds, and if so should I reduce this to a short time e.g. 1 second?
<p style="line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" 2) <span style="font-size:12pt; font-family:"Times New Roman","serif" If I comment out this winService.WaitForStatus(ServiceControllerStatus.Running,
timeout); line, what are the possible problems i.e. can I be fairly confident that the service will be started with no WaitForStatus part? <hr class="sig Stephen
View the full article
the problem is that this sometimes leads to a .NET Broadcast message... , error when the user logs out, especially on Windows XP. I presume that this is because there is a conflict between the machine trying to logout and the
service starting timeout i.e. both trying to control things at the same time.
<p style="line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" I have been checking on this again (for example at www.csharp-examples.net/restart-windows-service), and this seems to be the way to start a service. However
to avoid these .NET Broadcast messages, I have since commented out these timeout lines so the service is called, and no waiting to ensure that this it has started. The other way that I can see of doing this is by starting the service earlier i.e. if
it looks like the user is going to log out, but then I have the problem of stopping it if the user doesnt log out.
<p style="line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" My outline code below for starting a service:
<p style="margin-bottom:0.0001pt; line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" if (serviceExists)<br/>
{<br/>
if (winService.Status == ServiceControllerStatus.Stopped || winService.Status
== ServiceControllerStatus.Paused)<br/>
{<br/>
TimeSpan timeout = TimeSpan.FromMilliseconds(10000);
//have commented out this line to avoid .NET Broadcast message<br/>
<br/>
winService.Start(args);<br/>
<br/>
winService.WaitForStatus(ServiceControllerStatus.Running,
timeout); //have commented out this line to avoid .NET Broadcast message<br/>
}<br/>
}
<p style="line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" So my questions are as below:
<p style="line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" 1) <span style="font-size:12pt; font-family:"Times New Roman","serif" Is there a need to allow this wait for the service to start for
10 seconds, and if so should I reduce this to a short time e.g. 1 second?
<p style="line-height:normal <span style="font-size:12pt; font-family:"Times New Roman","serif" 2) <span style="font-size:12pt; font-family:"Times New Roman","serif" If I comment out this winService.WaitForStatus(ServiceControllerStatus.Running,
timeout); line, what are the possible problems i.e. can I be fairly confident that the service will be started with no WaitForStatus part? <hr class="sig Stephen
View the full article