質問編集履歴
4
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -103,3 +103,47 @@
|
|
103
103
|
}
|
104
104
|
|
105
105
|
```
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
ログ出力ソフトのテストプログラム
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
private StreamWriter sw;
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
public Form1()
|
118
|
+
|
119
|
+
{
|
120
|
+
|
121
|
+
InitializeComponent();
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
sw = new StreamWriter(File.Open(@"C:\hoge\aaa.csv", FileMode.OpenOrCreate, FileAccess.Write,FileShare.Read),Encoding.Default);
|
126
|
+
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
private void button1_Click(object sender, EventArgs e)
|
132
|
+
|
133
|
+
{
|
134
|
+
|
135
|
+
sw.WriteLine(DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss"));
|
136
|
+
|
137
|
+
sw.Flush();
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
|
142
|
+
|
143
|
+
{
|
144
|
+
|
145
|
+
sw.Close();
|
146
|
+
|
147
|
+
}
|
148
|
+
|
149
|
+
```
|
3
ソース変更
test
CHANGED
File without changes
|
test
CHANGED
@@ -52,13 +52,15 @@
|
|
52
52
|
|
53
53
|
{
|
54
54
|
|
55
|
+
//デバッグログ出力
|
56
|
+
|
57
|
+
|
58
|
+
|
55
59
|
if (!isFileWatch)
|
56
60
|
|
57
61
|
{
|
58
62
|
|
59
63
|
isFileWatch = true;
|
60
|
-
|
61
|
-
|
62
64
|
|
63
65
|
|
64
66
|
|
2
ソース修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,9 +58,13 @@
|
|
58
58
|
|
59
59
|
isFileWatch = true;
|
60
60
|
|
61
|
-
//これがあるとダメ
|
62
61
|
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
//↓ここから
|
66
|
+
|
63
|
-
|
67
|
+
using (FileStream fs = new FileStream(e.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
64
68
|
|
65
69
|
{
|
66
70
|
|
@@ -82,7 +86,13 @@
|
|
82
86
|
|
83
87
|
fs.Close();
|
84
88
|
|
85
|
-
}
|
89
|
+
}
|
90
|
+
|
91
|
+
//↑ここまでがあるとダメです。
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
86
96
|
|
87
97
|
isFileWatch = false;
|
88
98
|
|
1
インデント追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -21,6 +21,8 @@
|
|
21
21
|
ファイル読込時のソースをどのようにしたらよいでしょうか?
|
22
22
|
|
23
23
|
|
24
|
+
|
25
|
+
```
|
24
26
|
|
25
27
|
fileWatcher = new System.IO.FileSystemWatcher();
|
26
28
|
|
@@ -58,7 +60,7 @@
|
|
58
60
|
|
59
61
|
//これがあるとダメ
|
60
62
|
|
61
|
-
**using (FileStream fs = new FileStream(
|
63
|
+
**using (FileStream fs = new FileStream(e.FullName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
62
64
|
|
63
65
|
{
|
64
66
|
|
@@ -87,3 +89,5 @@
|
|
87
89
|
}
|
88
90
|
|
89
91
|
}
|
92
|
+
|
93
|
+
```
|