-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFrmSplashScreen.cs
More file actions
58 lines (50 loc) · 1.72 KB
/
FrmSplashScreen.cs
File metadata and controls
58 lines (50 loc) · 1.72 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
56
57
58
using GeoTagNinja.Helpers;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace GeoTagNinja;
public partial class FrmSplashScreen : Form
{
private Stopwatch stopWatch = new();
public FrmSplashScreen()
{
InitializeComponent();
}
[DllImport(dllName: "User32.dll")]
[return: MarshalAs(unmanagedType: UnmanagedType.Bool)]
private static extern bool SetForegroundWindow(IntPtr hWnd);
private const int MIN_WAIT_TIME_BEFORE_CLOSE_MSEC = 1200;
private void FrmSplashScreen_Load(object sender,
EventArgs e)
{
HelperNonStatic helperNonStatic = new();
helperNonStatic.CenterForm(frm: this);
_ = SetForegroundWindow(hWnd: Handle);
stopWatch.Start();
}
/// <summary>
/// Updates the progress - just so that things don't look totally stupid there is a 1.2 sec wait before closing
/// assuming tasks have actually finished.
/// </summary>
/// <param name="amount"></param>
/// <param name="close"></param>
internal void UpdateProgress(int amount,
bool close)
{
_ = BeginInvoke(method: new MethodInvoker(delegate
{
pbr_Splash.Increment(value: amount);
if (close)
{
while (stopWatch.Elapsed < TimeSpan.FromMilliseconds(value: MIN_WAIT_TIME_BEFORE_CLOSE_MSEC))
{
Application.DoEvents();
Thread.Sleep(timeout: new TimeSpan(days: 0, hours: 0, minutes: 0, seconds: 0, milliseconds: 100));
}
Close();
}
}));
}
}