WPF's use of System.Windows.Threading.DispatcherTimer (repeat doing something every once in a while)

Source: Internet
Author: User

A progress bar is used here to show

Previous section code:

1<window x:class="Timertest.mainwindow"2xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"3xmlns:x="Http://schemas.microsoft.com/winfx/2006/xaml"4title="MainWindow"height=" -"Width="525">5<Grid>6<button content="Button"Horizontalalignment=" Left"margin="241,249,0,0"Verticalalignment="Top"Width=" the"click="Button_Click"/>7<progressbar x:name="PB"minimum="0"maximum=" -"Horizontalalignment=" Left"height=" the"margin="10,151,0,0"Verticalalignment="Top"Width="497"/>8 9</Grid>Ten</Window>
View Code

Background code:

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Text;5 usingSystem.Threading.Tasks;6 usingSystem.Windows;7 usingSystem.Windows.Controls;8 usingSystem.Windows.Data;9 usingSystem.Windows.Documents;Ten usingSystem.Windows.Input; One usingSystem.Windows.Media; A usingSystem.Windows.Media.Imaging; - usingSystem.Windows.Navigation; - usingSystem.Windows.Shapes; the usingSystem.Windows.Threading; -  - namespacetimertest - { +     /// <summary> -     ///Interaction logic for MainWindow.xaml +     /// </summary> A      Public Partial classMainwindow:window at     { -          PublicMainWindow () -         { - InitializeComponent (); -         } -  in         Private voidButton_Click (Objectsender, RoutedEventArgs e) -         { toDispatcherTimer DispatcherTimer =NewDispatcherTimer (); +Dispatchertimer.tick + =NewEventHandler (Dispatchertimer_tick); -Dispatchertimer.interval =NewTimeSpan (0,0,1); the Dispatchertimer.start (); *         } $ Panax Notoginseng         Private voidDispatchertimer_tick (Objectsender, EventArgs e) -         { thePb. Value + =3; +         } A     } the}
View Code

WPF's use of System.Windows.Threading.DispatcherTimer (repeat doing something every once in a while)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.