質問編集履歴
2
GetIsConnect\(\)のelse{};の;削除,CopyFolder\(\)の定義・呼び元に引数追加,ExeCommandTaskの型・内容変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -124,7 +124,7 @@
|
|
124
124
|
|
125
125
|
if (result.Contains(ping送信成功を示す特定の文字列)) {return 1;} ・・・★1.ここには来る
|
126
126
|
|
127
|
-
else {return 0;}
|
127
|
+
else {return 0;}
|
128
128
|
|
129
129
|
}
|
130
130
|
|
@@ -142,7 +142,7 @@
|
|
142
142
|
|
143
143
|
while (true) {
|
144
144
|
|
145
|
-
if (copy.CopyFolder().Result == 1) {// コピー成功と判定}
|
145
|
+
if (copy.CopyFolder(m_CTSTaskB).Result == 1) {// コピー成功と判定}
|
146
146
|
|
147
147
|
else {// 失敗と判定}
|
148
148
|
|
@@ -162,17 +162,17 @@
|
|
162
162
|
|
163
163
|
◆/* @brief ネットワーク越しのフォルダ間コピーを行う */
|
164
164
|
|
165
|
-
public async Task<int> CopyFolder()
|
165
|
+
public async Task<int> CopyFolder(CancellationTokenSource cts)
|
166
166
|
|
167
167
|
{
|
168
168
|
|
169
169
|
CCommon common = new CCommon();
|
170
170
|
|
171
|
-
string result = await common.ExeCommandTask(
|
171
|
+
string result = await common.ExeCommandTask(cts, "copy コピー元フォルダ コピー先フォルダ");
|
172
172
|
|
173
173
|
if (result.Contains(copy成功を示す特定の文字列)) {return 1;} ・・・★2.ここには来ない
|
174
174
|
|
175
|
-
else {return 0;}
|
175
|
+
else {return 0;}
|
176
176
|
|
177
177
|
}
|
178
178
|
|
@@ -184,7 +184,7 @@
|
|
184
184
|
|
185
185
|
◆/* @brief コマンドをプロセスで実行するタスク */
|
186
186
|
|
187
|
-
public Task ExeCommandTask(CancellationTokenSource cts, string command)
|
187
|
+
public Task<string> ExeCommandTask(CancellationTokenSource cts, string command)
|
188
188
|
|
189
189
|
{
|
190
190
|
|
@@ -210,10 +210,16 @@
|
|
210
210
|
|
211
211
|
// コマンドをOSのプロセスで実行し、1秒ごとに実行完了待ちを行い、同時にタスクキャンセル要求が
|
212
212
|
|
213
|
+
// ないか確認する
|
214
|
+
|
213
|
-
//
|
215
|
+
// 実行完了すれば実行結果をresultに得て、プロセスをクローズする
|
214
216
|
|
215
217
|
process.Start();
|
216
218
|
|
219
|
+
string result = process.StandardOutput.ReadToEnd();
|
220
|
+
|
221
|
+
|
222
|
+
|
217
223
|
while (true) {
|
218
224
|
|
219
225
|
process.WaitForExit(1000);
|
@@ -226,6 +232,8 @@
|
|
226
232
|
|
227
233
|
process.Close();
|
228
234
|
|
235
|
+
return result;
|
236
|
+
|
229
237
|
}
|
230
238
|
|
231
239
|
|
@@ -236,6 +244,8 @@
|
|
236
244
|
|
237
245
|
if (!process.HasExited) {process.Kill();}
|
238
246
|
|
247
|
+
return "";
|
248
|
+
|
239
249
|
}
|
240
250
|
|
241
251
|
}, cts.Token, TaskCreationOptions.AttachedToParent, TaskScheduler.Default);
|
1
GetIsConnect\(\)の呼び元に\.Result追加,CopyFolder\(\)の呼び元に\.Result追加,CopyFolder\(\)の戻り値void→Task<int>に修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -98,7 +98,7 @@
|
|
98
98
|
|
99
99
|
while (true) {
|
100
100
|
|
101
|
-
if (GetIsConnect() == 1) {// 接続と判定}
|
101
|
+
if (GetIsConnect().Result == 1) {// 接続と判定}
|
102
102
|
|
103
103
|
else {// 切断と判定}
|
104
104
|
|
@@ -142,7 +142,7 @@
|
|
142
142
|
|
143
143
|
while (true) {
|
144
144
|
|
145
|
-
if (copy.CopyFolder() == 1) {// コピー成功と判定}
|
145
|
+
if (copy.CopyFolder().Result == 1) {// コピー成功と判定}
|
146
146
|
|
147
147
|
else {// 失敗と判定}
|
148
148
|
|
@@ -162,7 +162,7 @@
|
|
162
162
|
|
163
163
|
◆/* @brief ネットワーク越しのフォルダ間コピーを行う */
|
164
164
|
|
165
|
-
public async
|
165
|
+
public async Task<int> CopyFolder()
|
166
166
|
|
167
167
|
{
|
168
168
|
|