jjzjj

dispatcherTimer

全部标签

c# - 让用户指定定时器时间?

我希望DispatcherTimer从文本框中读取时间值:objTextBox。我尝试了这段代码,但似乎TimeSpan与字符串不兼容,还是我做错了什么?错误:参数1:无法从“string”转换为“long”还有;文本框中的时间是否必须如下所示:0、0、1或00:00:01?代码在这里:privatevoidtesting(){stringtheText=objTextBox.Text;DispatcherTimerdispatcherTimer=newDispatcherTimer();dispatcherTimer.Tick+=newEventHandler(listjob3_Ti

windows - 如何设置 DispatcherTimer 的优先级?

我正在使用C#中的Silverlight创建适用于WindowsPhone7的应用。我发现许多对DispatcherTimer(DispatcherPriority)重载的引用,但我无法在我的代码中设置它(例如timer=newDispatcherTimer(DispatcherPriority)告诉我“DispatcherPriority在当前上下文中不存在”)。我认为DispatcherTimer被DispatcherTimer(DispatcherPriority)重载了,但是当我在我的代码中使用它时,我看不到任何对此构造函数的引用。我想尝试将优先级设置为“正常”或“发送”,但我

c# - Task.Delay 与 DispatcherTimer?

我正在考虑将Task.Delay()用于不间断计时器,因为它更简单且可读性更强。由于我是.NET的新手,我看不出这两种代码之间有什么显着差异。你能告诉我它们之间的区别(如果有的话)吗?//CreatevariableatsomeplaceDispatcherTimertimer=newDispatcherTimer();timer.Interval=TimeSpan.FromSeconds(5);timer.Tick+=timer_Elapsed;timer.Start();//Functionotherplacevoidtimer_Elapsed(objectsender,Event

c# - 如何在 wpf 后台执行任务,同时能够提供报告并允许取消?

我想在单击wpf按钮后执行长时间运行的任务。这是我所做的。privatevoidStart(objectsender,RoutedEventArgse){for(inti=0;i问题是,这会使wpfgui无响应。我还想允许取消并每1秒报告一次进度。我将代码展开如下。DispatcherTimerdispatcherTimer=newDispatcherTimer();//getprogresseverysecondprivateintprogress=0;//forprogressreportingprivateboolisCancelled=false;//cancellationp

c# - DispatcherTimer 应用间隔并立即执行

基本上,当我们应用某个时间间隔(即5秒)时,我们必须等待它。是否可以应用间隔并立即执行计时器而不等待5秒?(我指的是间隔时间)。有什么线索吗?谢谢!!publicpartialclassMainWindow:Window{DispatcherTimertimer=newDispatcherTimer();publicMainWindow(){InitializeComponent();timer.Tick+=newEventHandler(timer_Tick);this.Loaded+=newRoutedEventHandler(MainWindow_Loaded);}voidtim

c# - 如何重置 DispatcherTimer?

这些是我的DispatcherTimer声明和方法:privateDispatcherTimerDishTimer;privateTimeSpanSpanTime;privatevoidInitTimer(){DishTimer=newDispatcherTimer();DishTimer.Interval=newTimeSpan(0,0,0,1);DishTimer.Tick+=TimerOnTick;}privatevoidTimerOnTick(objectsender,objecto){SpanTime=SpanTime.Add(DishTimer.Interval);Dura

c# - 之前的 "new"运算符会怎样?

DispatcherTimerdt=newDispatcherTimer();dt.Interval=newTimeSpan(0,0,0,0,100);dt.Tick+=newEventHandler(dt_dt);我对new关键字有疑问。我有一个设置为间隔的DispatcherTimer。假设用户想要更改间隔。dt.Interval=newTimeSpan(0,0,0,0,50);那么,第一个newTimeSpan会发生什么?它还在那里吗?还是新的会覆盖旧的?我不这么认为。如果我想更改时间间隔,new关键字是否是声明新TimeSpan的唯一方法?我问这个,因为我不确定每次值更改时声明

c# - DispatcherTimer 未触发 Tick 事件

我有一个DispatcherTimer,我已经像这样初始化了:staticDispatcherTimer_timer=newDispatcherTimer();staticvoidMain(){_timer.Interval=newTimeSpan(0,0,5);_timer.Tick+=newEventHandler(_timer_Tick);_timer.Start();}staticvoid_timer_Tick(objectsender,EventArgse){//dosomething}_timer_Tick事件从未被触发,我是不是错过了什么? 最

c# - UWP App 中未链接到 UI 的计时器

我正在开发一个UWPMVVM项目,并希望在用户交互停止特定时间后实现自动注销系统。到目前为止,我一直在使用DispatcherTimer每秒从200倒数。TimerLeave=200;var_dispatcherTimer=newDispatcherTimer();_dispatcherTimer.Tick+=dispatcherTimer_Tick;_dispatcherTimer.Interval=newTimeSpan(0,0,1);_dispatcherTimer.Start();但是因为链接了DispatcherTimer使用UI并且我正在构建一个MVVM应用程序,我正在寻找

c# - DispatcherTimer的 'IsEnabled'和 'Start/Stop'有什么区别?

我认为IsEnabled=false/true与类System.Windows.Threading.DispatcherTimer的Stop/Start方法相同我说得对吗?[编辑]Start():以完整的间隔倒计时开始计时器。IsEnabled=false:暂停计时器,间隔倒计时保持不变。IsEnabled=true:恢复计时器并继续上次使用的间隔倒计时。Stop():停止计时器,间隔倒计时会重置吗? 最佳答案 考虑到Start/Stop会切换IsEnabled属性,您的假设很接近。Start/Stop不同,因为Interval已重
12