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组件时,调用组件 ...
随机推荐
- Android-自定义开关
效果图: 需要两张图片,一张图片为背景,一张图片为滑动的点 布局去指定一个自定义View对象: view.custom.shangguigucustomview.MyCustomSwitch < ...
- Android-GsonUtil工具类
JSON解析封装相关工具类 public class GsonUtil { private static Gson gson = null; static { if (gson == null) { ...
- MySQL 笔记整理(20) --幻读是什么,幻读有什么问题?
笔记记录自林晓斌(丁奇)老师的<MySQL实战45讲> (本篇内图片均来自丁奇老师的讲解,如有侵权,请联系我删除) 20) --幻读是什么,幻读有什么问题? 我们先来看看表结构和初始化数据 ...
- Tomcat 配置用户认证服务供C#客户端调用
项目里,遇到的一个小问题来好好的总结一下.因为我们这个项目是用Java写的服务端发布WebService,客户端呢使用C#来调用WebService(本人以前搞过一段时间C#客户端,还总结了一个MVP ...
- 使用Team Explorer Everywhere (TEE) 2015 SDK获取团队项目的签入策略
TFS的代码签入策略与IDE工具紧密相关,例如Visual Studio中设置的签入策略,只会影响Visual Studio的团队资源管理器:如果需要在Eclipse的TEE中启用签入策略,你还需要在 ...
- mysql5.7 column cannot be null
背景 独立测试环境安装了数据库,但安装的版本是mysql 5.7的版本,而研发用的是mysql5.6的版本,在执行某个数据库操作的提示,提示column “xxxx”cannot be null 问题 ...
- ClamAV学习【1】——ClamAV流程
不知道是对还是错,一开始就上手学习ClamAV,享受被虐的过程吧. 发现ClamAV的官网也很少资料,搜商还有待加强,大概翻阅了example的源代码,明白了其查毒的大概方式(BM和AC算法匹配特征码 ...
- Java中 IO类 - File类中的判断功能
package com.hxzy.IOSer;import java.io.*;public class Demo05 { public static void main(String[] args) ...
- 洛谷P3676 小清新数据结构题(动态点分治+树链剖分)
传送门 感觉这题做下来心态有点崩……$RMQ$求$LCA$没有树剖快我可以理解为是常数太大……然而我明明用了自以为不会退化的点分然而为什么比会退化的点分跑得反而更慢啊啊啊啊~~~ 先膜一波zsy大佬 ...
- S2-052复现过程(附POC利用)
漏洞编号:CVE-2017-9805(S2-052) 影响版本:Struts 2.5 - Struts 2.5.12 漏洞概述:问题出现在struts2-rest-plugin插件XStreamHan ...