Fix crash in ErrorReporter because api thread is not STA
This commit is contained in:
1 parent
e9f3e92f82
commit
082056ea3f
1 file changed
+11
-8
@@ -7,7 +7,7 @@ using mbts.ui;
|
||||
using System;
|
||||
using System.ComponentModel.Composition;
|
||||
using System.Reactive.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Threading;
|
||||
using System.Windows;
|
||||
|
||||
namespace bts.spark
|
||||
@@ -29,11 +29,14 @@ namespace bts.spark
|
||||
Disposable.dispose(ref _dispose);
|
||||
}
|
||||
|
||||
public async Task report_error(string message, string title = null, MessageBoxImage? image = null) {
|
||||
var result = await BTSMessageBox.ShowAsync(message, title = "Error", BTSMessageBoxButtons.OK | BTSMessageBoxButtons.Support, image ?? MessageBoxImage.Error);
|
||||
if (result == BTSMessageBoxButtons.Support) {
|
||||
show_support_window(message, title);
|
||||
}
|
||||
public void report_error(string message, string title = null, MessageBoxImage? image = null) {
|
||||
// Error reports are likely to arrive the api thread (which is not an STA thread)
|
||||
Application.Current.Dispatcher.BeginInvoke(async () => {
|
||||
var result = await BTSMessageBox.ShowAsync(message, title = "Error", BTSMessageBoxButtons.OK | BTSMessageBoxButtons.Support, image ?? MessageBoxImage.Error);
|
||||
if (result == BTSMessageBoxButtons.Support) {
|
||||
show_support_window(message, title);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void show_support_window(string message, string title) {
|
||||
@@ -70,11 +73,11 @@ namespace bts.spark
|
||||
return (get_successful_rv(result.value), string.Empty);
|
||||
else {
|
||||
string error_msg = template.fmt(error);
|
||||
error_reporter.report_error(error_msg).ignore();
|
||||
error_reporter.report_error(error_msg);
|
||||
return (get_unsuccessful_rv(), error_msg);
|
||||
}
|
||||
} else {
|
||||
error_reporter.report_error(result.error_message).ignore();
|
||||
error_reporter.report_error(result.error_message);
|
||||
return (get_unsuccessful_rv(), result.error_message);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user