blob: 448e27f55c89eccab49b92d17dc0cc4cca011209 (
plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Threading;
namespace Tango.FirmwareUpdateLib.WPF
{
public class ProgressDispatcher
{
private Dispatcher _dispatcher;
private Window _dummyWindow; //Dummy window for the video dispatcher.
private Thread _windowThread; //The video dispatcher thread.
private bool _initialized;
public void Initialize()
{
if (!_initialized)
{
_windowThread = new Thread(VideoThreadMethod);
_windowThread.Name = "Progress Thread";
_windowThread.SetApartmentState(ApartmentState.STA);
_windowThread.Start();
while (!_initialized)
{
Thread.Sleep(10);
}
}
}
private void VideoThreadMethod()
{
_dummyWindow = new Window();
_dummyWindow.Width = 0;
_dummyWindow.Height = 0;
_dummyWindow.WindowStyle = WindowStyle.None;
_dummyWindow.ShowInTaskbar = false;
_dummyWindow.ShowActivated = false;
_dummyWindow.ResizeMode = ResizeMode.NoResize;
_dummyWindow.Visibility = Visibility.Hidden;
_dummyWindow.Opacity = 0;
_dummyWindow.Closed += (x, y) => _dummyWindow.Dispatcher.InvokeShutdown();
_dummyWindow.Loaded += (x, y) =>
{
_dummyWindow.Width = 0;
_dummyWindow.Height = 0;
_dummyWindow.WindowStyle = WindowStyle.None;
_dummyWindow.ShowInTaskbar = false;
_dummyWindow.ShowActivated = false;
_dummyWindow.ResizeMode = ResizeMode.NoResize;
_dummyWindow.Visibility = Visibility.Hidden;
_dummyWindow.Opacity = 0;
_dispatcher = _dummyWindow.Dispatcher;
_initialized = true;
};
Debug.WriteLine("Progress Dispatcher Initialized!");
_dummyWindow.Show();
Dispatcher.Run();
}
public void Invoke(Action action)
{
_dispatcher.BeginInvoke(action);
}
public void Close()
{
_dispatcher.InvokeShutdown();
}
}
}
|