-
Notifications
You must be signed in to change notification settings - Fork 55
/
Copy pathCommander.cs
85 lines (71 loc) · 2.08 KB
/
Commander.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
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
85
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace DigitalPlatform.CommonControl
{
public class Commander
{
public event IsBusyEventHandler IsBusy = null;
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
List<int> messages = new List<int>();
Form form = null;
public Commander(Form form)
{
this.form = form;
this.timer.Tick -= new EventHandler(timer_Tick);
this.timer.Tick += new EventHandler(timer_Tick);
}
void timer_Tick(object sender, EventArgs e)
{
if (this.IsBusy != null)
{
IsBusyEventArgs e1 = new IsBusyEventArgs();
this.IsBusy(this, e1);
if (e1.IsBusy == true)
return;
lock (this.messages)
{
for (int i = 0; i < this.messages.Count; i++)
{
API.PostMessage(this.form.Handle, this.messages[i], 0, 0);
}
this.messages.Clear();
}
this.timer.Stop();
}
}
public void AddMessage(int value)
{
lock (this.messages)
{
this.messages.Add(value);
}
this.timer.Start();
}
public void Destroy()
{
lock (this.messages)
{
this.messages.Clear();
}
this.timer.Stop();
this.timer.Tick -= new EventHandler(timer_Tick);
}
}
/// <summary>
/// 是否繁忙?
/// </summary>
/// <param name="sender">发送者</param>
/// <param name="e">事件参数</param>
public delegate void IsBusyEventHandler(object sender,
IsBusyEventArgs e);
/// <summary>
/// 是否繁忙事件的参数
/// </summary>
public class IsBusyEventArgs : EventArgs
{
public bool IsBusy = false; // [out]
}
}