質問編集履歴
1
当該箇所のコード(概要)を追記しました。 -- 2019/08/13
test
CHANGED
File without changes
|
test
CHANGED
@@ -57,3 +57,97 @@
|
|
57
57
|
よろしくお願いします。
|
58
58
|
|
59
59
|
以上です。
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
以下、追記です。
|
64
|
+
|
65
|
+
### 当該部分のコードは以下のようにしています。
|
66
|
+
|
67
|
+
※そのまま書けないので、概要化しています。
|
68
|
+
|
69
|
+
```C#
|
70
|
+
|
71
|
+
// データを処理する部分
|
72
|
+
|
73
|
+
using( var connection = new MySqlConnection( connection_string ) )
|
74
|
+
|
75
|
+
{
|
76
|
+
|
77
|
+
connection.Open();
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
Parallel.For( 0, 3, id =>
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
while( !<終了条件> )
|
86
|
+
|
87
|
+
{
|
88
|
+
|
89
|
+
// <sql> を用意する
|
90
|
+
|
91
|
+
// <param> を用意する
|
92
|
+
|
93
|
+
var res = GetData( connection, <sql>, <param> );
|
94
|
+
|
95
|
+
// res をいろいろする
|
96
|
+
|
97
|
+
}
|
98
|
+
|
99
|
+
});
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
// DB にアクセスする部分
|
106
|
+
|
107
|
+
public DataTable[] GetData( MySqlConnection connection, string sql, Hashtable param )
|
108
|
+
|
109
|
+
{
|
110
|
+
|
111
|
+
var ret = new List<DataTable>();
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
using( var command = new MySqlCommand( sql, connection ) )
|
116
|
+
|
117
|
+
{
|
118
|
+
|
119
|
+
foreach( DictionaryEntry item in <param> )
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
coomand.Parameters.Add( new MySqlParameter( item.Key.ToString(), item.Value ?? System.DBNull.Value ) );
|
124
|
+
|
125
|
+
}
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
using( var adapter = new MySqlDataAdapter( command ) )
|
130
|
+
|
131
|
+
{
|
132
|
+
|
133
|
+
using( var ds = new DataSet() )
|
134
|
+
|
135
|
+
{
|
136
|
+
|
137
|
+
lock( this ) adapter.Fill( ds );
|
138
|
+
|
139
|
+
foreach( Data.DataTable item in ds.Tables ) ret.Add( item );
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
}
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
return ret.ToArray();
|
150
|
+
|
151
|
+
}
|
152
|
+
|
153
|
+
```
|