Tomasz
Wed Oct 18 12:18:47 CDT 2006
Hi Kevin,
No, I create counters *before*
"System.ServiceProcess.ServiceBase.Run(ServicesToRun)".
Moving call to a method creating counters to the OnStart() was the *only
change* I made. The behavior is/was very consistent.
I do not understand why, but it helped.
Tomasz
"Kevin Yu [MSFT]" <v-kevy@online.microsoft.com> wrote in message
news:pLRrpho8GHA.3352@TK2MSFTNGXA01.phx.gbl...
> Hi Tomasz,
>
> I tried the same code in the Main() method, and it's working fine. Did you
> put the code after System.ServiceProcess.ServiceBase.Run(ServicesToRun)?
> If
> true, it might be the case that your code hangs. We should put it before
> the service itself starts. My code that is working fine looks like the
> follwing.
>
> ' The main entry point for the process
> <MTAThread()> _
> <System.Diagnostics.DebuggerNonUserCode()> _
> Shared Sub Main()
> Dim ServicesToRun() As System.ServiceProcess.ServiceBase
>
> ' More than one NT Service may run within the same process. To add
> ' another service to this process, change the following line to
> ' create a second service object. For example,
> '
> ' ServicesToRun = New System.ServiceProcess.ServiceBase () {New
> Service1, New MySecondUserService}
> '
> Const ThisServiceName As String = "My Service"
>
> Trace.WriteLine("Checking performance counters category.")
> If PerformanceCounterCategory.Exists(ThisServiceName) Then
> Trace.WriteLine("Deleting performance counters.")
> PerformanceCounterCategory.Delete(ThisServiceName)
> Trace.WriteLine("Performance counters deleted.")
> End If
>
> PerformanceCounterCategory.Create(ThisServiceName, "",
> PerformanceCounterCategoryType.MultiInstance, "test counter", "")
>
> ServicesToRun = New System.ServiceProcess.ServiceBase() {New
> Service1}
> System.ServiceProcess.ServiceBase.Run(ServicesToRun)
> End Sub
>
> Furthermore, it is not suggested to put your code in the main method. You
> can put it in the OnStart method. And start your service in another thread
> that does the main jobs.
>
> If anything is unclear, please feel free to let me know.
>
> Kevin Yu
> 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.)
>