-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormMain.cs
73 lines (60 loc) · 2.12 KB
/
FormMain.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
using MultiThreading.Models;
namespace MultiThreading
{
public partial class FormMain : Form
{
public FormMain()
{
InitializeComponent();
LogManager.Default.OnLogAdded += (s, e) => { AddLog(e); };
}
private void AddLog(string logMessage)
{
if (lbLogs.InvokeRequired)
{
lbLogs.Invoke(new Action(() => AddLog(logMessage)));
return;
}
logMessage = $"[{DateTime.Now:dd.MM.yyy HH:mm:ss:fff}] - {logMessage}";
lbLogs.Items.Add(logMessage);
lbLogs.SelectedIndex = lbLogs.Items.Count - 1;
}
private void btnListMailTasks_Click(object sender, EventArgs e)
{
var smtpMailTask = new MailTask(MailProviderType.Smtp)
{
Second = 10
};
var googleMailTask = new MailTask(MailProviderType.GoogleMail)
{
Second = 60
};
mailTaskBindingSource.Clear();
mailTaskBindingSource.Add(smtpMailTask);
mailTaskBindingSource.Add(googleMailTask);
}
private void mailTaskBindingSource_CurrentItemChanged(object sender, EventArgs e)
{
var mailTask = mailTaskBindingSource.Current as MailTask;
if (mailTask == null) return;
btnStartTask.Enabled = !mailTask.IsStarted;
btnStopTask.Enabled = mailTask.IsStarted;
btnRunTask.Enabled = mailTask.IsStarted && !mailTask.IsRunning;
}
private void btnStopTask_Click(object sender, EventArgs e)
{
var mailTask = mailTaskBindingSource.Current as MailTask;
mailTask.Stop();
}
private async void btnRunTask_Click(object sender, EventArgs e)
{
var mailTask = mailTaskBindingSource.Current as MailTask;
await mailTask.Run(100);
}
private void btnStartTask_Click(object sender, EventArgs e)
{
var mailTask = mailTaskBindingSource.Current as MailTask;
mailTask.Start();
}
}
}