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
|
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
namespace dlg1
{
public class MonitorData
{
// データ取得タイマー
private System.Windows.Forms.Timer _timer = new System.Windows.Forms.Timer();
public delegate void GetTableDataDelegate(DataTable dt);
public GetTableDataDelegate GetTableDataDelegateProc = null;
public MonitorData()
{
_timer.Interval = 3000;
_timer.Tick += new EventHandler(_timer_Tick);
_timer.Start();
}
void _timer_Tick(object sender, EventArgs e)
{
_timer.Stop();
try
{
DataTable dt = new DataTable();
GetTableAData(ref dt);
// デリゲートで呼び出し
if (GetTableDataDelegateProc != null)
{
GetTableDataDelegateProc(dt);
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
_timer.Start();
}
}
private void GetTableAData(ref DataTable dt)
{
dt.Clear();
DataRow dr = null;
// 列を定義
dt.Columns.Add("A", Type.GetType("System.String"));
dt.Columns.Add("B", Type.GetType("System.String"));
dt.Columns.Add("C", Type.GetType("System.String"));
// データを格納
for (int i = 1; i <= 5; i++)
{
dr = dt.NewRow();
dr["A"] = "A_" + i.ToString("00");
dr["B"] = "B_" + i.ToString("00");
dr["C"] = "C_" + i.ToString("00");
dt.Rows.Add(dr);
}
}
}
}
|