forked from MscrmTools/XrmToolBox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWorker.cs
More file actions
84 lines (74 loc) · 2.62 KB
/
Copy pathWorker.cs
File metadata and controls
84 lines (74 loc) · 2.62 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.ComponentModel;
using System.Windows.Forms;
namespace XrmToolBox.Extensibility
{
public class Worker
{
private Panel _infoPanel;
private BackgroundWorker _worker;
public void CancelWorker()
{
if (_worker != null && _worker.WorkerSupportsCancellation)
{
_worker.CancelAsync();
if (_infoPanel != null)
{
_infoPanel.Parent.Controls.Remove(_infoPanel);
_infoPanel.Dispose();
}
}
}
public void SetWorkingMessage(Control host, string message, int width = 340, int height = 150)
{
if (host.Controls.Contains(_infoPanel))
{
if (_infoPanel.Width != width || _infoPanel.Height != height)
{
_infoPanel.Dispose();
host.Controls.Remove(_infoPanel);
_infoPanel = InformationPanel.GetInformationPanel(host, message, width, height);
}
else
{
InformationPanel.ChangeInformationPanelMessage(_infoPanel, message);
}
}
else
{
_infoPanel = InformationPanel.GetInformationPanel(host, message, width, height);
}
}
public void WorkAsync(WorkAsyncInfo info)
{
if (info.Host == null)
{
throw new NullReferenceException("WorkAsyncInfo Host property is null!");
}
_infoPanel = InformationPanel.GetInformationPanel(info.Host, info.Message, info.MessageWidth, info.MessageHeight);
_worker = new BackgroundWorker
{
WorkerReportsProgress = info.ProgressChanged != null,
WorkerSupportsCancellation = info.IsCancelable
};
_worker.DoWork += info.PerformWork;
if (_worker.WorkerReportsProgress && info.ProgressChanged != null)
{
_worker.ProgressChanged += info.PerformProgressChange;
}
if (info.PostWorkCallBack != null)
{
_worker.RunWorkerCompleted += (s, e) =>
{
if (info.Host.Controls.Contains(_infoPanel))
{
_infoPanel.Dispose();
info.Host.Controls.Remove(_infoPanel);
}
info.PostWorkCallBack(e);
};
}
_worker.RunWorkerAsync(info.AsyncArgument);
}
}
}