hytos / DTI_PID / SPPIDConverter_AutoModeling / ProgressForm.cs @ 4077103a
이력 | 보기 | 이력해설 | 다운로드 (9.17 KB)
1 | b33b0d0a | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.ComponentModel; |
||
4 | using System.Data; |
||
5 | using System.Threading; |
||
6 | using System.Drawing; |
||
7 | using System.Text; |
||
8 | using System.Windows.Forms; |
||
9 | using Telerik.WinControls; |
||
10 | using Telerik.WinControls.UI; |
||
11 | using System.Diagnostics; |
||
12 | |||
13 | namespace SPPIDConverter_AutoModeling |
||
14 | { |
||
15 | public partial class ProgressForm : RadForm |
||
16 | { |
||
17 | private static ProgressForm progress; |
||
18 | Thread thread; |
||
19 | Stopwatch sw; |
||
20 | System.Timers.Timer timer; |
||
21 | public static bool stop = false; |
||
22 | |||
23 | public ProgressForm() |
||
24 | { |
||
25 | InitializeComponent(); |
||
26 | } |
||
27 | |||
28 | private void radButtonCancel_Click(object sender, EventArgs e) |
||
29 | { |
||
30 | if (thread.IsAlive) |
||
31 | { |
||
32 | try |
||
33 | { |
||
34 | ManualResetEvent manualReset = new ManualResetEvent(false); |
||
35 | Thread message = new Thread(func => |
||
36 | { |
||
37 | DialogResult dialogResult = MessageBox.Show("Are you sure you want to cancel?", "Question", MessageBoxButtons.OKCancel, MessageBoxIcon.Question); |
||
38 | if (dialogResult == DialogResult.Cancel) |
||
39 | { |
||
40 | manualReset.Set(); |
||
41 | } |
||
42 | else |
||
43 | { |
||
44 | try |
||
45 | { |
||
46 | stop = true; |
||
47 | manualReset.Set(); |
||
48 | thread.Abort(); |
||
49 | } |
||
50 | catch (Exception ex) |
||
51 | { |
||
52 | |||
53 | } |
||
54 | } |
||
55 | }); |
||
56 | message.Start(); |
||
57 | manualReset.WaitOne(); |
||
58 | } |
||
59 | catch (Exception ex) |
||
60 | { |
||
61 | |||
62 | } |
||
63 | finally |
||
64 | { |
||
65 | |||
66 | } |
||
67 | } |
||
68 | |||
69 | if (stop) |
||
70 | DialogResult = DialogResult.Cancel; |
||
71 | } |
||
72 | |||
73 | public static void Start(Thread thread) |
||
74 | { |
||
75 | try |
||
76 | { |
||
77 | if (progress == null) |
||
78 | { |
||
79 | progress = new ProgressForm(); |
||
80 | } |
||
81 | |||
82 | progress.thread = thread; |
||
83 | progress.thread.IsBackground = false; |
||
84 | if (progress.thread != null) |
||
85 | progress.thread.Start(); |
||
86 | progress.sw = new Stopwatch(); |
||
87 | progress.sw.Start(); |
||
88 | progress.timer = new System.Timers.Timer(); |
||
89 | progress.timer.Interval = 100; |
||
90 | progress.timer.Elapsed += new System.Timers.ElapsedEventHandler(progress.timer_Elapsed); |
||
91 | progress.timer.Start(); |
||
92 | progress.ShowDialog(); |
||
93 | } |
||
94 | catch (Exception ex) |
||
95 | { |
||
96 | SPPID.Utill.Log.WriteLine(ex); |
||
97 | } |
||
98 | |||
99 | } |
||
100 | |||
101 | public static void End() |
||
102 | { |
||
103 | if (progress != null) |
||
104 | { |
||
105 | if (progress.InvokeRequired) |
||
106 | { |
||
107 | progress.BeginInvoke(new Action(() => CloseForm())); |
||
108 | } |
||
109 | else |
||
110 | { |
||
111 | CloseForm(); |
||
112 | } |
||
113 | } |
||
114 | } |
||
115 | |||
116 | private static void CloseForm() |
||
117 | { |
||
118 | progress.timer.Stop(); |
||
119 | progress.sw.Stop(); |
||
120 | progress.DialogResult = DialogResult.OK; |
||
121 | progress = null; |
||
122 | } |
||
123 | |||
124 | public static void UpdateDocument(string text) |
||
125 | { |
||
126 | if (progress != null) |
||
127 | { |
||
128 | if (progress.labelDocument.InvokeRequired) |
||
129 | { |
||
130 | progress.labelDocument.BeginInvoke(new Action(() => progress.labelDocument.Text = text)); |
||
131 | Thread.Sleep(1); |
||
132 | } |
||
133 | else |
||
134 | { |
||
135 | progress.labelDocument.Text = text; |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | |||
140 | public static void UpdateTime(string text) |
||
141 | { |
||
142 | if (progress != null) |
||
143 | { |
||
144 | if (progress.labelTime.InvokeRequired) |
||
145 | { |
||
146 | progress.labelTime.BeginInvoke(new Action(() => progress.labelTime.Text = text)); |
||
147 | Thread.Sleep(1); |
||
148 | } |
||
149 | else |
||
150 | { |
||
151 | progress.labelTime.Text = text; |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | |||
156 | public static void UpdateStatus(string text) |
||
157 | { |
||
158 | if (progress != null) |
||
159 | { |
||
160 | if (progress.labelStatus.InvokeRequired) |
||
161 | { |
||
162 | progress.labelStatus.BeginInvoke(new Action(() => progress.labelStatus.Text = text)); |
||
163 | Thread.Sleep(1); |
||
164 | } |
||
165 | else |
||
166 | { |
||
167 | progress.labelStatus.Text = text; |
||
168 | } |
||
169 | } |
||
170 | } |
||
171 | |||
172 | public static void SetProgressStatusMax(int maxValue) |
||
173 | { |
||
174 | if (progress != null) |
||
175 | { |
||
176 | if (progress.progressBarStatus.InvokeRequired) |
||
177 | { |
||
178 | progress.progressBarStatus.BeginInvoke(new Action(() => progress.progressBarStatus.Maximum = maxValue)); |
||
179 | Thread.Sleep(1); |
||
180 | } |
||
181 | else |
||
182 | { |
||
183 | progress.progressBarStatus.Maximum = maxValue; |
||
184 | } |
||
185 | } |
||
186 | } |
||
187 | |||
188 | public static void SetProgressStatusValue(int value) |
||
189 | { |
||
190 | if (progress != null) |
||
191 | { |
||
192 | if (progress.progressBarStatus.InvokeRequired) |
||
193 | { |
||
194 | progress.progressBarStatus.BeginInvoke(new Action(() => progress.progressBarStatus.Value1 = value)); |
||
195 | Thread.Sleep(1); |
||
196 | } |
||
197 | else |
||
198 | { |
||
199 | progress.progressBarStatus.Value1 = value; |
||
200 | } |
||
201 | } |
||
202 | } |
||
203 | |||
204 | public static void SetProgressStatusMax() |
||
205 | { |
||
206 | if (progress != null) |
||
207 | { |
||
208 | if (progress.progressBarStatus.InvokeRequired) |
||
209 | { |
||
210 | progress.progressBarStatus.BeginInvoke(new Action(() => progress.progressBarStatus.Value1 = progress.progressBarStatus.Maximum)); |
||
211 | Thread.Sleep(1); |
||
212 | } |
||
213 | else |
||
214 | { |
||
215 | progress.progressBarStatus.Value1 = progress.progressBarStatus.Maximum; |
||
216 | } |
||
217 | } |
||
218 | } |
||
219 | |||
220 | public static void IncreaseProgressStatus() |
||
221 | { |
||
222 | if (progress != null) |
||
223 | { |
||
224 | if (progress.progressBarStatus.Maximum > progress.progressBarStatus.Value1) |
||
225 | { |
||
226 | if (progress.progressBarStatus.InvokeRequired) |
||
227 | { |
||
228 | progress.progressBarStatus.BeginInvoke(new Action(() => progress.progressBarStatus.ProgressBarElement.IncrementValue1(1))); |
||
229 | Thread.Sleep(1); |
||
230 | } |
||
231 | else |
||
232 | { |
||
233 | progress.progressBarStatus.ProgressBarElement.IncrementValue1(1); |
||
234 | } |
||
235 | } |
||
236 | } |
||
237 | } |
||
238 | |||
239 | |||
240 | public static void SetProgressAllValue(int value) |
||
241 | { |
||
242 | if (progress != null) |
||
243 | { |
||
244 | if (progress.progressBarAll.InvokeRequired) |
||
245 | { |
||
246 | progress.progressBarAll.BeginInvoke(new Action(() => progress.progressBarAll.Value1 = value)); |
||
247 | Thread.Sleep(1); |
||
248 | } |
||
249 | else |
||
250 | { |
||
251 | progress.progressBarAll.Value1 = value; |
||
252 | } |
||
253 | } |
||
254 | } |
||
255 | |||
256 | public static void IncreaseProgressAll() |
||
257 | { |
||
258 | if (progress != null) |
||
259 | { |
||
260 | if (progress.progressBarAll.Maximum > progress.progressBarAll.Value1) |
||
261 | { |
||
262 | if (progress.progressBarAll.InvokeRequired) |
||
263 | { |
||
264 | progress.progressBarAll.BeginInvoke(new Action(() => progress.progressBarAll.ProgressBarElement.IncrementValue1(1))); |
||
265 | Thread.Sleep(1); |
||
266 | } |
||
267 | else |
||
268 | { |
||
269 | progress.progressBarAll.ProgressBarElement.IncrementValue1(1); |
||
270 | } |
||
271 | } |
||
272 | } |
||
273 | } |
||
274 | |||
275 | public static void SetProgressAllMax() |
||
276 | { |
||
277 | if (progress != null) |
||
278 | { |
||
279 | if (progress.progressBarAll.InvokeRequired) |
||
280 | { |
||
281 | progress.progressBarAll.BeginInvoke(new Action(() => progress.progressBarAll.Value1 = progress.progressBarAll.Maximum)); |
||
282 | Thread.Sleep(1); |
||
283 | } |
||
284 | else |
||
285 | { |
||
286 | progress.progressBarAll.Value1 = progress.progressBarAll.Maximum; |
||
287 | } |
||
288 | } |
||
289 | } |
||
290 | |||
291 | private void timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) |
||
292 | { |
||
293 | TimeSpan ts = sw.Elapsed; |
||
294 | string elapsedTime = String.Format("{0:00}:{1:00}", |
||
295 | ts.Minutes, ts.Seconds); |
||
296 | UpdateTime(elapsedTime); |
||
297 | } |
||
298 | } |
||
299 | } |