Unhandled exception does not stop service

701 views
Skip to first unread message

Johan Nilsson

unread,
Feb 3, 2014, 11:48:34 AM2/3/14
to topshelf...@googlegroups.com
Unhandled exception is being thrown, but the stop functionality is not invoked nor is the service terminated. 
Service keeps on doing it's work.

Any ideas as to why?

Dru Sellers

unread,
Feb 3, 2014, 11:52:04 AM2/3/14
to topshelf...@googlegroups.com
can you give us a bit more context about your application?


--
You received this message because you are subscribed to the Google Groups "topshelf-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topshelf-discu...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Johan Nilsson

unread,
Feb 3, 2014, 11:57:55 AM2/3/14
to topshelf...@googlegroups.com
Sure, anything in particular?

It does a lot of work involving tasks.
When connection to a third party goes down, we recognize this and throw an exception, expecting topshelf to take care of it.
It doesn't.

Completely lost here as to why, currently i'm guessing at how topshelf is supposed to work but failing miserably.

Sorry for the vague details, anything else i can fill in?
Thanks
Best Regards

Travis Smith

unread,
Feb 3, 2014, 12:00:26 PM2/3/14
to topshelf...@googlegroups.com
Unhandled exceptions with Tasks don't bubble to the AppDomain, right? So there's nothing for Topshelf to handle. 
--
-Travis

Johan Nilsson

unread,
Feb 3, 2014, 12:23:43 PM2/3/14
to topshelf...@googlegroups.com
Ah good idea Travis!

Managed to catch it with TaskScheduler.UnobservedTaskException

Thanks alot!

Btw any thoughts about creating a jabbr channel?
Best Regards
Johan Nilsson
To unsubscribe from this group and stop receiving emails from it, send an email to topshelf-discuss+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.


--
-Travis

Johan Nilsson

unread,
Feb 3, 2014, 12:27:35 PM2/3/14
to topshelf...@googlegroups.com
Although only seems to work while debugging.
Will try to handle exceptions better.
Message has been deleted

Johan Nilsson

unread,
Feb 3, 2014, 2:32:24 PM2/3/14
to topshelf...@googlegroups.com
Ok still digging.
So it seems the method throwing the exception expected to be caught by topshelf is triggered from an System.EventHandler by a System.Timers.Timer

Does that help?
I guess I have to bring that back to the main topshelf thread somehow?

Thanks!

Travis Smith

unread,
Feb 3, 2014, 2:37:14 PM2/3/14
to topshelf...@googlegroups.com
What version of .NET? http://msdn.microsoft.com/en-us/library/system.timers.timer(v=vs.110).aspx

There's behaviour to suppress exceptions on a Timer. I think can change the behaviour in 4.0/4.5 but requires app.config changes. 


--
-Travis

Johan Nilsson

unread,
Feb 3, 2014, 2:47:42 PM2/3/14
to topshelf...@googlegroups.com
.Net 4. Although it's not an exception happening in the timer, it's an eventhandler being invoked

Thanks

Travis Smith

unread,
Feb 3, 2014, 2:55:27 PM2/3/14
to topshelf...@googlegroups.com
If it's from the Timer, it's from the same thread. Unless you do context switching - you would know you're doing that because you would explicitly have to do it. 
-Travis

Johan Nilsson

unread,
Feb 3, 2014, 2:57:57 PM2/3/14
to topshelf...@googlegroups.com
Hmm then it's even weirder that topshelf and my Appdomain.Current.unhandledexceptions doesn't catch it.
I'm lost..

Anything else that could cause the exception to not get to topshelf.
I can debug and see the throw new Exception happening, but after that nothing. the service just continues.

Thanks

Travis Smith

unread,
Feb 3, 2014, 3:23:26 PM2/3/14
to topshelf...@googlegroups.com
Sorry, if it's an event raised from a Timer, it's on the same thread as the Timer. Not as the main thread. Timer will gobble the exception and it won't bubble to the AppDomain. Sorry if that was unclear. 

-Travis
Reply all
Reply to author
Forward
0 new messages