I have a form that I'm calling a class that creates a filewatcher and does varies other things when the filewatcher fires. If an error occurs during the the filewatcher changed event, I need to let the main form know there was an issue.
My filewatcher class:
internal static class PpsTransactionFileWatcher
{
private static FileSystemWatcher _watcher;
public static Suburban.Miscellaneous.Response StartPpsFileWatcher()
{
var response = new Suburban.Miscellaneous.Response();
response.IsSuccess = true;
response.Message = "Success";
try
{
CreateTrnFileWatcher();
ProcessTransactionFile();
return response;
}
catch (Exception ex)
{
LoggingWrapper.Log("StartPpsFileWatcher", ex.ToString(), ex);
response.IsSuccess = false;
response.Message = ex.Message;
return response;
}
}
private static void CreateTrnFileWatcher()
{
try
{
_watcher = new FileSystemWatcher
{
Path = GlobalSettings.PpsDirectory,
NotifyFilter = NotifyFilters.LastWrite,
Filter = GlobalSettings.PpsTransactionFile
};
_watcher.Changed += TrnWatcherChanged;
_watcher.EnableRaisingEvents = true;
}
catch (Exception ex)
{
LoggingWrapper.Log("CreateTrnFileWatcher", ex.ToString(), ex);
throw;
}
}
private static void TrnWatcherChanged(object sender, FileSystemEventArgs e)
{
try
{
_watcher.Changed -= TrnWatcherChanged;
ProcessTransactionFile();
_watcher.Changed += TrnWatcherChanged;
}
catch (Exception ex)
{
LoggingWrapper.Log("TrnWatcherChanged", ex.ToString(), ex);
}
}
}
On my form, I'm calling it like this:
var transresponse = PpsTransactionFileWatcher.StartPpsFileWatcher();
How would I notify my form that there was an exception thrown from this class after it's started from the changed event?