-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAppUpdateCoordinator.cs
More file actions
55 lines (48 loc) · 1.86 KB
/
Copy pathAppUpdateCoordinator.cs
File metadata and controls
55 lines (48 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
using System.Diagnostics;
using System.Threading;
using System.Windows;
using System.Windows.Threading;
namespace ArIED61850Tester;
internal static class AppUpdateCoordinator
{
private static readonly TimeSpan LazyStartupDelay = TimeSpan.FromSeconds(15);
private static int _started;
public static async Task RunLazyAsync(CancellationToken cancellationToken)
{
if (Interlocked.Exchange(ref _started, 1) != 0)
return;
try
{
await Task.Delay(LazyStartupDelay, cancellationToken).ConfigureAwait(false);
var application = Application.Current;
if (application is null || application.Dispatcher.HasShutdownStarted)
return;
using var service = new AppUpdateService();
var manifest = await service.CheckForUpdateAsync(cancellationToken).ConfigureAwait(false);
if (manifest is null || cancellationToken.IsCancellationRequested)
return;
await application.Dispatcher.InvokeAsync(
() =>
{
if (application.MainWindow is not Window owner || !owner.IsVisible)
return;
var prompt = new UpdatePromptWindow(service, manifest)
{
Owner = owner
};
prompt.ShowDialog();
},
DispatcherPriority.Background,
cancellationToken);
}
catch (OperationCanceledException)
{
// Application shutdown or a cancelled background check requires no user-facing error.
}
catch (Exception exception)
{
// Update availability must never block startup or interrupt IEC 61850 work.
Debug.WriteLine($"ARSAS lazy update check failed: {exception}");
}
}
}