Hey I am having an issue with an application that I have created. Basically for the first few weeks I am trying to step in to catch all first chance exceptions log them to the database and continue as normal. Now here's the sticker I do not want the application to close. I just want to log the error and continue, so app.quit etc is not what I am looking for. If it hit's the unhandled exception I have a seperate error handler for that. This is fine but it is causing multiple instances of word to open and is causing my system to crash from out of memory. So my question is does anyone have an idea on how to best implement this or any suggestions on how to fix this?
And the code is pretty simple.
AppDomain currentDomain = AppDomain.CurrentDomain;
currentDomain.FirstChanceException += LogException;
public async Task LogException(string exception)
{
var word = new Microsoft.Office.Interop.Word.Application();
var winVer = Environment.OSVersion.ToString();
CiteRightException exceptionData = new CiteRightException();
exceptionData.stackTrace = exception;
exceptionData.windowsVersion = word.Version;
exceptionData.windowsVersion = winVer;
var content = new StringContent(Json.Encode(exceptionData),
Encoding.UTF8, "application/json");
await httpClient.PostAsync("/api/logException", content);
}
I have tried using a .quit method (Did not stop extra instances opening) and thinking it might be a thread issue currentThread.join() but still new instances are being created. If I comment out the firstchanceexception line everything works fine so it is 100% coming from here.
Thanks very much in advance