WPF的System.Windows.Threading.DispatcherTimer的使用(每隔一定的时间重复做某事)
这里使用了一个进度条来展示,
前段代码:
<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 += ;
}
}
}
WPF的System.Windows.Threading.DispatcherTimer的使用(每隔一定的时间重复做某事)的更多相关文章
- silverlight 定时器 System.Windows.Threading.DispatcherTimer
声明 System.Windows.Threading.DispatcherTimer _MessageControler; //刷新 _MessageControler = new System.W ...
- 线程:主线程、子线程 同步线程、异步线程 单线程、多线程 System.Threading与System.Windows.Threading
入门-------------------------------------------------------------------------------- 概述与概念 一个C#程序开始 ...
- windows server 2008 r2, 每隔一段时间自动关机
前段时间在做Exchange 2010测试的时候,由于windows server 2008 r2试用过期,开机后二个小时就会自动关机,可是我又不想重装系统,加为那样我可能需要重装好多东西,包括 ...
- WPF使用System.Windows.SystemParameters类获得屏幕分辨率
转自 http://hi.baidu.com/shirley_cst/item/a55c290c8aa2ee2ca0312da3 示例代码如下所示. double x = SystemParamete ...
- WPF 问题 PresentationCore.dll!System.Windows.Media.Composition.DUCE.Channel.SyncFlush() 分析
错误信息: 没有足够的内存继续执行程序 在 System.Windows.Media.Composition.DUCE.Channel.SyncFlush() 在 System.Windows.Int ...
- WPF中的多进程(Threading)处理实例(一)
原文:WPF中的多进程(Threading)处理实例(一) 说明:希望通过揣摩这些案例,能进一步了解进程的工作原理. 1.方法一描述的是在同一窗口中,在计算素数的同时而不影响Canvas的工作. 方法 ...
- 开发客户端软件时,出现System.Windows.Markup.XamlParseException错误
开发客户端软件时,出现System.Windows.Markup.XamlParseException错误,通过查看错误消息,发现TCPIP的一个COM组件在安装软件过程中被删除了,重新注册了一下TC ...
- System.Windows.Forms.Timer、System.Timers.Timer、System.Threading.Timer的 区别和用法
System.Windows.Forms.Timer执行的时候,如果你在过程中间加一个sleep整个的界面就死掉了,但是另外两个没有这个情况,System.Timers.Timer.System.Th ...
- WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常
WPF中实例化Com组件,调用组件的方法时报System.Windows.Forms.AxHost+InvalidActiveXStateException的异常 在wpf中封装Com组件时,调用组件 ...
随机推荐
- Postgresql fillfactor
一个表的填充因子(fillfactor)是一个介于 10 和 100 之间的百分数.100(完全填充)是默认值.如果指定了较小的填充因子,INSERT 操作仅按照填充因子指定的百分率填充表页.每个页上 ...
- windows通过命令方式解压zip文件
1.需要下载unzip 地址:http://gnuwin32.sourceforge.net/packages/unzip.htm 下载exe版本 2.安装后将bin目录下的unzip.exe文件放在 ...
- 解决vs2017调试出现脚本错误(/Community/Common7/IDE/PrivateAssemblies/plugin.vs.js) 方法
原文地址:http://bkcoding.cn/post_1204.html 新装的vs2017编译时出现当前页面脚本错误 url:/Community/Common7/IDE/PrivateAsse ...
- cesium随笔 — 简单实现获取三维范围(包括相机高度)
代码 // 获取当前三维范围 function getCurrentExtent() { // 范围对象 var extent = {}; // 得到当前三维场景 var scene = viewer ...
- WP8.1StoreApp(WP8.1RT)---MessageBox与MessageDialog
在WP7和WP8中,MessageBox是跟WinForm中一样常用的对话框,但是有一个显著的缺点,就是WP7/8中默认的MessageBox是阻塞线程的.也许是由于这个原因,WP8.1/Win8中采 ...
- 如何使用jQuery实现根据不同IP显示不同的内容
一些SEM的投放页会针对不同地域做针对性的内容推广,下面我把实现方法分享出来. 一.引用新浪提供的IP查询的js库 <script src="http://int.dpool.sina ...
- Java多线程编程:Callable、Future和FutureTask浅析(多线程编程之四)
java多线程-概念&创建启动&中断&守护线程&优先级&线程状态(多线程编程之一)java多线程同步以及线程间通信详解&消费者生产者模式&死锁& ...
- iOS 获取 UITabViewController 和 UINavigationController 的图标位置
这些图标是放在 UITabBar 和 UINavigationBar 里的.所以只要遍历它们的 subViews,找到类型是 UIButton 的就可以了. 所有想获取它们的相对位置很容易. 获取到相 ...
- kolla-ansible安装openstack(Ocata)
基本功能部署 基础环境 角色 操作系统 硬件配置 Depoly CentOS 7 Server 磁盘:40GB 内存:8GB 网卡:ens3(内网) ens4(外网) Sched CentOS 7 S ...
- fatal: Not a git repository (or any parent up to mount point /home)
问题:fatal: Not a git repository (or any parent up to mount point /home) 解决:git init