public async void Run() { _logger.logInfo("MyScript Batch Recognizer started"); _logger.logInfo("Listening to directory " + _path); _logger.logInfo(""); _logger.logRemaining(); bool _stop = false; while (!_stop) { _stop = Convert(); System.Threading.Thread.Sleep(10); App.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { })); } App app = (App)(Application.Current); app.Shutdown(); }