-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm1.cs
60 lines (51 loc) · 1.57 KB
/
Form1.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
using System.Diagnostics.Eventing.Reader;
namespace cslibs
{
public partial class Form1 : Form
{
public Form1()
{
this._task = null;
InitializeComponent();
}
private UIBackTask<string, bool, string>? _task;
private void UIBackTaskNotify(string _v)
{
this.tbUIBackTask.Text += System.Environment.NewLine + _v;
}
private bool UIBackTaskFunc(string _arg, Func<string, bool> _notify)
{
// テストタスク
for ( int _i = 0; _i < 1000; _i++ )
{
// キャンセルされたら抜ける
if (_notify($"test {_i:d}")) break;
Thread.Sleep(10);
}
return false;
}
private void btnTestUIBackTask_Click(object sender, EventArgs e)
{
// UIBackTaskクラスのテスト
if (this._task != null)
{
// 停止
this._task?.CanelAndWait(false);
this.btnUIBackTask.Text = "UIBackTestのテスト";
this._task = null;
}
else
{
// 開始
this._task = new UIBackTask<string, bool, string>(this);
this._task.Execute(this.UIBackTaskFunc, "Test", this.UIBackTaskNotify);
this.btnUIBackTask.Text = "Cancel";
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
// タスクを終了させる
this._task?.CanelAndWait(true);
}
}
}