Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Windows.Forms;
- using System.Threading;
- namespace WinFormsThreading
- {
- public partial class Form1 : Form
- {
- Thread myThread;
- public Form1()
- {
- InitializeComponent();
- myThread = new Thread(countDown);
- }
- private void button1_Click(object sender, EventArgs e)
- {
- myThread.Start();
- }
- private void countDown()
- {
- for (int i = 5; i >= 0; i--)
- {
- label1.Invoke(new MethodInvoker(delegate //Invoke to the "dispatcher" that belongs to the UI thread
- {
- label1.Text = Convert.ToString(i);
- }
- ));
- Thread.Sleep(1000);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment