Skip to content
Browse files

cleaned up UnobservedEvent code

  • Loading branch information...
1 parent aefc31f commit 05ec0af0768d2bfef22fd298623762fe4ddfa935 @sethwebster sethwebster committed Apr 15, 2012
Showing with 12 additions and 4 deletions.
  1. +12 −4 Jabbot/Bot.cs
View
16 Jabbot/Bot.cs
@@ -44,12 +44,13 @@ internal List<ISprocket> Sprockets
private ComposablePartCatalog _catalog = null;
private CompositionContainer _container = null;
- private bool _isActive = false;
+ private bool _globalEventsWired = false;
private bool _containerInitialized = false;
public Bot(string url, string name, string password)
{
- TaskScheduler.UnobservedTaskException += new EventHandler<UnobservedTaskExceptionEventArgs>(TaskScheduler_UnobservedTaskException);
+ InitializeGlobalEvents();
+
Name = name;
_url = url;
_password = password;
@@ -59,9 +60,16 @@ public Bot(string url, string name, string password)
InitializeContainer();
}
- void TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)
+ private void InitializeGlobalEvents()
{
- WriteDebugInfo(e.Exception.GetBaseException().ToString());
+ if (!_globalEventsWired)
+ {
+ TaskScheduler.UnobservedTaskException += (sender, e) =>
+ {
+ WriteDebugInfo(e.Exception.GetBaseException().ToString());
+ };
+ }
+ _globalEventsWired = true;
}
private void InitializeClient()

0 comments on commit 05ec0af

Please sign in to comment.
Something went wrong with that request. Please try again.