質問編集履歴

1

作成したソースコード追加

2019/06/05 13:35

投稿

f_tonakai
f_tonakai

スコア15

test CHANGED
File without changes
test CHANGED
@@ -32,6 +32,192 @@
32
32
 
33
33
 
34
34
 
35
+ ```ここに言語を入力
36
+
35
-  シングルスレッドでは動かないのでしょうか?
37
+ // Form1.cs
38
+
39
+
40
+
36
-
41
+ namespace TestSample {
42
+
43
+ public partial class Form1 : Form {
44
+
45
+
46
+
47
+ private int isProcessing;
48
+
49
+
50
+
51
+ public Form1() {
52
+
53
+ isProcessing = 0;
54
+
55
+ InitializeComponent();
56
+
57
+ }
58
+
59
+
60
+
37
-  デバッグ実行でも確認できません。button1_Clickメソッドに入りません
61
+ private void button1_Click(object sender, EventArgs e) {
62
+
63
+
64
+
65
+ if(isProcessing == 1) {
66
+
67
+ return;
68
+
69
+ }
70
+
71
+
72
+
73
+ isProcessing = 1;
74
+
75
+ this.button1.Click -= new System.EventHandler(this.button1_Click);
76
+
77
+ this.button2.Click -= new System.EventHandler(this.button2_Click);
78
+
79
+
80
+
81
+ // テキストに数字を出力(テスト用で簡易なロジック実装)
82
+
83
+ DataOutPut dataOutPut = new DataOutPut("[start]", "[end]");
84
+
85
+ dataOutPut.OutPutFile();
86
+
87
+
88
+
89
+ isProcessing = 0;
90
+
91
+ Application.DoEvents();
92
+
93
+ this.button1.Click += new System.EventHandler(this.button1_Click);
94
+
95
+ this.button2.Click += new System.EventHandler(this.button2_Click);
96
+
97
+
98
+
99
+ return;
100
+
101
+
102
+
103
+ }
104
+
105
+
106
+
107
+ private void button2_Click(object sender, EventArgs e) {
108
+
109
+ this.Close();
110
+
111
+ return;
112
+
113
+ }
114
+
115
+
116
+
117
+ private void Form1_Closing(object sender, FormClosingEventArgs e) {
118
+
119
+ if (isProcessing == 1) {
120
+
121
+ Console.WriteLine("★ -- No Form1_Closing() -- ★");
122
+
123
+ e.Cancel = true;
124
+
125
+ }
126
+
127
+ }
128
+
129
+ }
130
+
131
+ }
132
+
133
+ ```
134
+
135
+
136
+
137
+ ```ここに言語を入力
138
+
139
+ // DataOutPut.cs
140
+
141
+
142
+
143
+ namespace TestSample {
144
+
145
+ class DataOutPut {
146
+
147
+
148
+
149
+ private string startCode;
150
+
151
+ private string endCode;
152
+
153
+
154
+
155
+ public DataOutPut(string startCode, string endCode) {
156
+
157
+ this.startCode = startCode;
158
+
159
+ this.endCode = endCode;
160
+
161
+ }
162
+
163
+
164
+
165
+ // テキストファイルに出力
166
+
167
+ public int OutPutFile() {
168
+
169
+
170
+
171
+ string filePath = @"C:\Users\fujiwarak\Desktop\work\";
172
+
173
+ string fileName = "test_";
174
+
175
+ string dt = (DateTime.Now).ToString("yyyyMMddHHmmss");
176
+
177
+ Encoding enc = Encoding.GetEncoding("Shift_JIS");
178
+
179
+
180
+
181
+ int index = 0;
182
+
183
+ while (index < 3) {
184
+
185
+ string filePathName = filePath + fileName + index.ToString() + dt + ".txt";
186
+
187
+ using (StreamWriter writer = new StreamWriter(filePathName, true)) {
188
+
189
+ writer.WriteLine(startCode);
190
+
191
+ int loop = 0;
192
+
193
+ int number = 0;
194
+
195
+ while (loop <= 10) {
196
+
197
+ System.Threading.Thread.Sleep(1000);
198
+
199
+ writer.WriteLine(number.ToString());
200
+
201
+ number++;
202
+
203
+ loop++;
204
+
205
+ }
206
+
207
+ writer.WriteLine(endCode);
208
+
209
+ }
210
+
211
+ index++;
212
+
213
+ }
214
+
215
+ return 0;
216
+
217
+ }
218
+
219
+ }
220
+
221
+ }
222
+
223
+ ```