using System.Collections.Generic;\r
using System.IO;\r
using System.Reflection;\r
+using System.Threading;\r
using System.Windows.Forms;\r
using Radegast.Commands;\r
using Radegast.Netcom;\r
public RadegastInstance(GridClient client0)\r
{\r
// incase something else calls GlobalInstance while we are loading\r
- globalInstance = this; \r
-\r
+ globalInstance = this;\r
+ Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);\r
+ Application.ThreadException += HandleThreadException;\r
client = client0;\r
\r
// Are we running mono?\r
\r
lock (PluginsLoaded)\r
{\r
- PluginsLoaded.ForEach(plug =>\r
+ List<IRadegastPlugin> unload = new List<IRadegastPlugin>(PluginsLoaded);\r
+ unload.ForEach(plug =>\r
{\r
+ PluginsLoaded.Remove(plug);\r
try\r
{\r
plug.StopPlugin(this);\r
}\r
- catch (Exception) { }\r
+ catch (Exception ex)\r
+ {\r
+ Logger.Log("ERROR in Shutdown Plugin: " + plug + " because " + ex, Helpers.LogLevel.Debug, ex);\r
+ }\r
});\r
}\r
\r
- movement.Dispose();\r
- movement = null;\r
- commandsManager.Dispose();\r
- commandsManager = null;\r
- ContextActionManager.Dispose();\r
- ContextActionManager = null;\r
- mediaManager.Dispose();\r
- mediaManager = null;\r
- state.Dispose();\r
- state = null;\r
- netcom.Dispose();\r
- netcom = null;\r
+ if (movement != null)\r
+ {\r
+ movement.Dispose();\r
+ movement = null;\r
+ }\r
+ if (commandsManager != null)\r
+ {\r
+ commandsManager.Dispose();\r
+ commandsManager = null;\r
+ }\r
+ if (ContextActionManager != null)\r
+ {\r
+ ContextActionManager.Dispose();\r
+ ContextActionManager = null;\r
+ }\r
+ if (mediaManager != null)\r
+ {\r
+ mediaManager.Dispose();\r
+ mediaManager = null;\r
+ }\r
+ if (state != null)\r
+ {\r
+ state.Dispose();\r
+ state = null;\r
+ }\r
+ if (netcom != null)\r
+ {\r
+ netcom.Dispose();\r
+ netcom = null;\r
+ }\r
+\r
Logger.Log("RadegastInstance finished cleaning up.", Helpers.LogLevel.Debug);\r
}\r
\r
{\r
get { return tabsConsole; }\r
}\r
+\r
+ public void HandleThreadException(object sender, ThreadExceptionEventArgs e)\r
+ {\r
+ Logger.Log("Unhandled Thread Exception: "+e.Exception + " in " +sender,Helpers.LogLevel.Error,client);\r
+ }\r
}\r
}\r