Thanks so much for your diligence. This might answer my question after all.
in the OnStop method or the OnShutDown method. It occurs in a thread pool
thread spawned when my timer.elapsed event is called.
""Jeffrey Tan[MSFT]"" wrote:
> Hi,
>
> Sorry for letting you wait.
>
> I finally found out the root cause. The OnStop method of ServiceBase is
> triggerred by ServiceBase.DeferredStop method. Using Reflector, we can see
> the source code like this:
>
> private unsafe void DeferredStop()
> {
> fixed (NativeMethods.SERVICE_STATUS* service_statusRef1 =
> &this.status)
> {
> int num1 = this.status.currentState;
> this.status.checkPoint = 0;
> this.status.waitHint = 0;
> this.status.currentState = 3;
> NativeMethods.SetServiceStatus(this.statusHandle,
> service_statusRef1);
> try
> {
> this.OnStop();
> this.WriteEventLogEntry(Res.GetString("StopSuccessful"));
> this.status.currentState = 1;
> NativeMethods.SetServiceStatus(this.statusHandle,
> service_statusRef1);
> }
> catch (StackOverflowException)
> {
> throw;
> }
> catch (OutOfMemoryException)
> {
> throw;
> }
> catch (ThreadAbortException)
> {
> throw;
> }
> catch (Exception exception1)
> {
> this.WriteEventLogEntry(Res.GetString("StopFailed", new
> object[] { exception1.ToString() }), EventLogEntryType.Error);
> this.status.currentState = num1;
> }
> }
> }
> As you can see, the DeferredStop method catched all the exceptions, so the
> exception in the OnStop method will not trigger our
> AppDomain.UnhandledException event. So was DeferredPause for OnPause
> method.
>
> 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.
>