質問編集履歴
2
コード部分をMarkdown気泡にて書き直し
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,61 +14,75 @@
|
|
14
14
|
|
15
15
|
# Read関数
|
16
16
|
|
17
|
+
```C#
|
18
|
+
|
17
19
|
public async Task Read(StorageFile file)
|
18
20
|
|
19
21
|
{
|
20
22
|
|
21
|
-
|
23
|
+
var buff = FileIO.ReadBufferAsync(file);
|
22
24
|
|
23
|
-
|
25
|
+
Encoding.Registerprovider(CodePagesEncodingProvider.Instance);
|
24
26
|
|
25
|
-
|
27
|
+
var enc = Encoding.GetEncoding("Shift_JIS");
|
26
28
|
|
27
|
-
|
29
|
+
lines = enc.GetString(buff.ToArray()).Split('\n');
|
28
30
|
|
29
|
-
|
31
|
+
(CSVからファイル名を取り出す処理)
|
30
32
|
|
31
33
|
}
|
34
|
+
|
35
|
+
```
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
32
40
|
|
33
41
|
|
34
42
|
|
35
43
|
# CopyFile関数
|
36
44
|
|
45
|
+
```C#
|
46
|
+
|
37
|
-
|
47
|
+
public async Task<bool> CopyFile()
|
48
|
+
|
49
|
+
{
|
50
|
+
|
51
|
+
foreach (ファイルの数だけ繰り返す)
|
52
|
+
|
53
|
+
{
|
54
|
+
|
55
|
+
inputFile = await StorageFile.GetFileFromPathAsync(入力ファイル名);
|
56
|
+
|
57
|
+
targetFolder = await StorageFolder.GetFolderFromPathAsync(出力先);
|
38
58
|
|
39
59
|
|
40
60
|
|
41
|
-
|
61
|
+
try
|
42
62
|
|
43
|
-
|
63
|
+
{
|
44
64
|
|
45
|
-
|
65
|
+
出力ファイル = await inputFile.CopyAsync(targetFolder);
|
46
66
|
|
67
|
+
}
|
68
|
+
|
47
|
-
|
69
|
+
catch (Exception)
|
70
|
+
|
71
|
+
{
|
72
|
+
|
73
|
+
ret = false;
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
}
|
78
|
+
|
79
|
+
return ret;
|
80
|
+
|
81
|
+
}
|
82
|
+
|
83
|
+
```
|
48
84
|
|
49
85
|
|
50
|
-
|
51
|
-
try
|
52
|
-
|
53
|
-
{
|
54
|
-
|
55
|
-
出力ファイル = await inputFile.CopyAsync(targetFolder);
|
56
|
-
|
57
|
-
}
|
58
|
-
|
59
|
-
catch (Exception)
|
60
|
-
|
61
|
-
{
|
62
|
-
|
63
|
-
ret = false;
|
64
|
-
|
65
|
-
}
|
66
|
-
|
67
|
-
}
|
68
|
-
|
69
|
-
return ret;
|
70
|
-
|
71
|
-
}
|
72
86
|
|
73
87
|
|
74
88
|
|
@@ -77,6 +91,8 @@
|
|
77
91
|
# ReadとCopyFileの呼び出し
|
78
92
|
|
79
93
|
|
94
|
+
|
95
|
+
```C#
|
80
96
|
|
81
97
|
private async Task<bool> ReadFile(StorageFile file)
|
82
98
|
|
@@ -94,6 +110,8 @@
|
|
94
110
|
|
95
111
|
}
|
96
112
|
|
113
|
+
```
|
114
|
+
|
97
115
|
|
98
116
|
|
99
117
|
この状態でやりたいことはRead関数の呼び出しの後、CopyFileを呼び出したいのですが、非同期処理のためCopyFileがReadの終了を待たずに実行されます。
|
1
ReadとCopyFileの呼び出し部分を追加。Read関数をasync呼び出しする箇所を修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,13 +12,19 @@
|
|
12
12
|
|
13
13
|
|
14
14
|
|
15
|
-
Read関数
|
15
|
+
# Read関数
|
16
16
|
|
17
17
|
public async Task Read(StorageFile file)
|
18
18
|
|
19
19
|
{
|
20
20
|
|
21
|
-
FileIO.ReadBufferAsync(file);
|
21
|
+
var buff = FileIO.ReadBufferAsync(file);
|
22
|
+
|
23
|
+
Encoding.Registerprovider(CodePagesEncodingProvider.Instance);
|
24
|
+
|
25
|
+
var enc = Encoding.GetEncoding("Shift_JIS");
|
26
|
+
|
27
|
+
lines = enc.GetString(buff.ToArray()).Split('\n');
|
22
28
|
|
23
29
|
(CSVからファイル名を取り出す処理)
|
24
30
|
|
@@ -26,7 +32,7 @@
|
|
26
32
|
|
27
33
|
|
28
34
|
|
29
|
-
CopyFile関数
|
35
|
+
# CopyFile関数
|
30
36
|
|
31
37
|
public async Task<bool> CopyFile() {
|
32
38
|
|
@@ -68,6 +74,28 @@
|
|
68
74
|
|
69
75
|
|
70
76
|
|
77
|
+
# ReadとCopyFileの呼び出し
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
private async Task<bool> ReadFile(StorageFile file)
|
82
|
+
|
83
|
+
{
|
84
|
+
|
85
|
+
bool ret;
|
86
|
+
|
87
|
+
Task task = Read(file);
|
88
|
+
|
89
|
+
task.Wait(); // これを入れるとReadの処理から戻らない。入れないと後のCopyFileがReadを待たずに実行される。
|
90
|
+
|
91
|
+
await CopyFile();
|
92
|
+
|
93
|
+
return true;
|
94
|
+
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
|
71
99
|
この状態でやりたいことはRead関数の呼び出しの後、CopyFileを呼び出したいのですが、非同期処理のためCopyFileがReadの終了を待たずに実行されます。
|
72
100
|
|
73
101
|
|