fix: deadlock in UI thread

This commit is contained in:
dantmnf
2023-04-01 15:59:03 +08:00
parent 4c4f8f4d6d
commit ab65e6ebf2
5 changed files with 105 additions and 73 deletions

View File

@@ -22,7 +22,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Threading;
using MaaWpfGui.Constants;
using MaaWpfGui.Extensions;
using MaaWpfGui.Helper;
@@ -171,12 +171,11 @@ namespace MaaWpfGui.ViewModels.UI
}
*/
private readonly Timer _timer = new Timer();
private readonly DispatcherTimer _timer = new DispatcherTimer();
private void InitTimer()
{
_timer.Enabled = true;
_timer.Interval = 1000 * 50;
_timer.Interval = TimeSpan.FromSeconds(50);
_timer.Tick += Timer1_Elapsed;
_timer.Start();
}
@@ -185,11 +184,14 @@ namespace MaaWpfGui.ViewModels.UI
{
if (NeedToUpdateDatePrompt())
{
Execute.OnUIThread(() =>
Task.Run(async () =>
{
_stageManager.UpdateStage(true);
UpdateDatePrompt();
UpdateStageList(false);
await _stageManager.UpdateStageWeb();
Execute.OnUIThread(() =>
{
UpdateDatePrompt();
UpdateStageList(false);
});
});
}
@@ -204,7 +206,7 @@ namespace MaaWpfGui.ViewModels.UI
{
if (_settingsViewModel.UpdatAutoCheck)
{
_settingsViewModel.ManualUpdate();
Task.Run(_settingsViewModel.ManualUpdate);
}
}