# DispatcherTimer 활용사례
using System;
using System.Windows.Threading;
using Systehttp://m.Windows.Forms;
using System.Timers;
using System.IO;
namespace APM
{
public partial class APMMain : Form
{
private DispatcherTimer displayTimer1 = new DispatcherTimer(); //유가
private DispatcherTimer displayTimer2 = new DispatcherTimer(); //코스닥
private DispatcherTimer displayTimer3 = new DispatcherTimer(); //파생
private DispatcherTimer displayTimer4 = new DispatcherTimer(); //채권
private int sec1, sec2, sec3, sec4;
public APMMain()
{
InitializeComponent();
InitControl();
}
void InitControl()
{
displayTimer1.Interval = TimeSpan.FromSeconds(interval);
displayTimer1.Tick += new EventHandler(displayTimer_Tick);
sec1 = 0;
displayTimer2.Interval = TimeSpan.FromSeconds(interval);
displayTimer2.Tick += new EventHandler(displayTimer_Tick);
sec2 = 0;
displayTimer3.Interval = TimeSpan.FromSeconds(interval);
displayTimer3.Tick += new EventHandler(displayTimer_Tick);
sec3 = 0;
displayTimer4.Interval = TimeSpan.FromSeconds(interval);
displayTimer4.Tick += new EventHandler(displayTimer_Tick);
sec4 = 0;
displayTimer1.Start();
displayTimer2.Start();
displayTimer3.Start();
displayTimer4.Start();
}
void displayTimer_Tick(object sender, EventArgs e)
{
if ((sender as DispatcherTimer).Equals(displayTimer1))
{
TimeSpan t = TimeSpan.FromSeconds(sec1++);
timer1.Text = string.Format("{0:D2}:{1:D2}", t.Minutes, t.Seconds);
}
else if ((sender as DispatcherTimer).Equals(displayTimer2))
{
TimeSpan t = TimeSpan.FromSeconds(sec2++);
timer2.Text = string.Format("{0:D2}:{1:D2}", t.Minutes, t.Seconds);
}
else if ((sender as DispatcherTimer).Equals(displayTimer3))
{
TimeSpan t = TimeSpan.FromSeconds(sec3++);
timer3.Text = string.Format("{0:D2}:{1:D2}", t.Minutes, t.Seconds);
}
else if ((sender as DispatcherTimer).Equals(displayTimer4))
{
TimeSpan t = TimeSpan.FromSeconds(sec4++);
timer4.Text = string.Format("{0:D2}:{1:D2}", t.Minutes, t.Seconds);
}
}
#region WndProc
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
default:
break;
}
base.WndProc(ref m);
}
#endregion
public void SetRegin()
{
//
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
}
}
'c# 언어 > 초급과정' 카테고리의 다른 글
(CHAT.GPT)클래스에서 다이얼로그 호출 시 메인 윈도우를 기준으로 위치 설정 (0) | 2024.06.03 |
---|---|
프로세스.종료 (0) | 2024.03.16 |
(Schedule)CHK.cs (0) | 2024.02.28 |
SetWindowLong 함수란 무엇인가 (0) | 2024.01.30 |
Windows Form 실행시에 Message 순서출력 (0) | 2024.01.06 |