Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Using Timer in WPF

    • 0
    • 2
    • 2
    • 0
    • 0
    • 0
    • 0
    • 0
    • 365
    Comment on it

    This is the demonstration of how to use a dispatch timer in WPF using C#.

    private DispatcherTimer timer; // Declaring instance of DispatcherTimer class

    public Window1()

    {

    InitializeComponent();
    Loaded += new RoutedEventHandler(Window1_Loaded);
    

    }

    void Window1_Loaded(object sender, RoutedEventArgs e)

    {

    timer = new DispatcherTimer(); // Initializing the timer
    
    timer.Interval = TimeSpan.FromSeconds(1); //Adding Timer Interval
    
    timer.Tick += timer1_Tick;  //Adding Tick Event for Timer.Tick function
    
    timer.Start();  //Starts Timer
    

    }

    private void timer1_Tick(object sender, EventArgs e)

    {

    timer.Stop(); //Stops Timer
    this.Close(); //Closes current form
    

    }

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: