This repository has been archived by the owner on Dec 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.xaml.cs
52 lines (46 loc) · 1.43 KB
/
App.xaml.cs
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
using System;
using System.Windows;
using System.Windows.Threading;
namespace mifi_status
{
/// <inheritdoc />
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App
{
private MainWindow _mainWindow;
private DispatcherTimer _dispatcherTimer;
private readonly TimeSpan _shortTimer = new TimeSpan(0, 0, 1);
private readonly TimeSpan _longTimer = new TimeSpan(0, 0, 8);
private void InitTimer()
{
if (_dispatcherTimer != null) return;
_dispatcherTimer = new DispatcherTimer {Interval = _shortTimer};
_dispatcherTimer.Start();
_dispatcherTimer.Tick += (sd, ea) => { HandleTimer(); };
}
void App_Startup(object sender, StartupEventArgs e)
{
InitTimer();
_mainWindow = new MainWindow();
_mainWindow.Show();
_mainWindow.RefreshData();
}
private void HandleTimer()
{
_mainWindow.RefreshData();
}
private void Application_Activated(object sender, EventArgs e)
{
InitTimer();
_mainWindow.RefreshData();
_dispatcherTimer.Interval = _shortTimer;
}
private void Application_Deactivated(object sender, EventArgs e)
{
InitTimer();
_dispatcherTimer.Interval = _longTimer;
}
}
}