WPF的System.Windows.Threading.DispatcherTimer的使用(每隔一定的时间重复做某事)
2024-08-23 01:16:05
这里使用了一个进度条来展示,
前段代码:
<Window x:Class="TimerTest.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="" Width="">
<Grid>
<Button Content="Button" HorizontalAlignment="Left" Margin="241,249,0,0" VerticalAlignment="Top" Width="" Click="Button_Click"/>
<ProgressBar x:Name="pb" Minimum="" Maximum="" HorizontalAlignment="Left" Height="" Margin="10,151,0,0" VerticalAlignment="Top" Width=""/> </Grid>
</Window>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Threading; namespace TimerTest
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
} private void Button_Click(object sender, RoutedEventArgs e)
{
DispatcherTimer dispatcherTimer = new DispatcherTimer();
dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick);
dispatcherTimer.Interval = new TimeSpan(, , );
dispatcherTimer.Start();
} private void dispatcherTimer_Tick(object sender, EventArgs e)
{
pb.Value += ;
}
}
}
最新文章
- bzoj2548[Cstc2002]灭鼠行动
- Activity 与 Service 之间的消息传递
- 咋一看DWoo 比 Smarty要好
- [SQL]SQL优化34条
- emWin使用外部SRAM的方法
- Android_Spinner_Listener
- map关联容器
- sctf pwn300
- MyEclipse 2015 Stable 2.0破解方法
- redis读书笔记
- 说一下Servlet里面得request和response
- 更改了react-redux 官方网站的todolist结构
- CentOS6.8 配置LVM
- fastcgi_next_upstream error timeout invalid_header http_500 http_503(转)
- BZOJ3419[POI2013]taxis——贪心
- 6609 - Minimal Subarray Length
- windows 环境下安装elasticsearch ,ik,head,marvel
- SSL学习笔记
- djngo 1.9版本以后 Foreignkey() 字段 第二个参数 on_delete 必不可少, mysql 外键可以为空
- 20155210潘滢昊 Java第二次试验