Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Timer_Tick(object sender,EventArgs e)
- {
- //lblTime.Content = DateTime.Now.ToLongTimeString();
- //lblTime.Content = DateTime.Now.ToString("HH:mm:ss:fff");
- //milliseconds++;
- //if (milliseconds >= 1000) {
- // sec++;
- // milliseconds = 0;
- //}
- //if (sec == 60) {
- // min++;
- // sec = 0;
- //}
- //lblTime.Content = string.Format("{0:00}:{1:00}:{2:D3}",min,sec,milliseconds);
- milliseconds += 15.560;
- if (milliseconds >= 1000) {
- milliseconds = 0;
- sec++;
- if (sec >= 60) {
- sec = 0;
- min++;
- }
- }
- lblTime.Content = min.ToString("00") + ":" + sec.ToString("00") + ":" +
- milliseconds.ToString("000").Substring(0,3);
- //lblTime.Content = String.Format("{0:00}:{1:00}:{2:000}", timer.Interval.Minutes, timer.Interval.Seconds, timer.Interval.Milliseconds);
- }
- private void Start(object sender,EventArgs e)
- {
- timer.Interval = TimeSpan.FromMilliseconds(1);
- timer.Tick += Timer_Tick;
- timer.Start();
- }
- public partial class MainWindow :Window
- {
- DispatcherTimer timer = new DispatcherTimer();
- int min = 0, sec = 0;
- double milliseconds = 0;
- public MainWindow()
- {
- InitializeComponent();
- }
- private void Timer_Tick(object sender,EventArgs e)
- {
- //lblTime.Content = DateTime.Now.ToLongTimeString();
- //lblTime.Content = DateTime.Now.ToString("HH:mm:ss:fff");
- //milliseconds++;
- //if (milliseconds >= 1000) {
- // sec++;
- // milliseconds = 0;
- //}
- //if (sec == 60) {
- // min++;
- // sec = 0;
- //}
- //lblTime.Content = string.Format("{0:00}:{1:00}:{2:D3}",min,sec,milliseconds);
- milliseconds += 15.560;
- if (milliseconds >= 1000) {
- milliseconds = 0;
- sec++;
- if (sec >= 60) {
- sec = 0;
- min++;
- }
- }
- lblTime.Content = min.ToString("00") + ":" + sec.ToString("00") + ":" +
- milliseconds.ToString("000").Substring(0,3);
- //lblTime.Content = String.Format("{0:00}:{1:00}:{2:000}", timer.Interval.Minutes, timer.Interval.Seconds, timer.Interval.Milliseconds);
- }
- private void Start(object sender,EventArgs e)
- {
- timer.Interval = TimeSpan.FromMilliseconds(1);
- timer.Tick += Timer_Tick;
- timer.Start();
- }
- }
- Stopwatch stopwatch = new Stopwatch();
- stopwatch.Start();
- for (; ;)
- {
- Console.WriteLine(stopwatch.Elapsed);
- }
Add Comment
Please, Sign In to add comment