timer

Throwing exceptions in callback method for Timers

旧巷老猫 提交于 2019-12-17 16:18:43
问题 I was unable to find an answer to this question anywhere... What happens with the exceptions thrown in the callback method for System.Threading.Timer, (or in the event handler for System.Timers.Timer). Is the exception propagated to the thread on which the timer was created or is the exception lost? What are the side-effects of throwing an exception within the timer's callback functions? What would be the right way to signalize to the timer's creation thread that the exception in the worker

Send notification once in a week

跟風遠走 提交于 2019-12-17 15:59:09
问题 I want to notify the user about answer the weekly questions.I need to send the notification to the user even my app is not running.The notification will send once in a week. When user clicks the notification my app will gets open. I tried this via Timer and TimerTask().This notifies the user when my app is running.How can I send the notification to the user while app is not running. Anyone can help me out? 回答1: The following code uses Alarmmanager with BroadcastReceiver which will help you

Timer in Java Thread

◇◆丶佛笑我妖孽 提交于 2019-12-17 15:57:09
问题 I have a thread which is in charge of doing some processes. I want make it so that these processing would be done every 3 seconds. I've used the code below but when the thread starts, nothing happens. I assumed that when I define a task for my timer it automatically execute the ScheduledTask within time interval but it doesn't do anything at all. What am I missing? class temperatureUp extends Thread { @Override public void run() { TimerTask increaseTemperature = new TimerTask(){ public void

Can Stopwatch be used in production code?

不打扰是莪最后的温柔 提交于 2019-12-17 15:53:13
问题 I need an accurate timer, and DateTime.Now seems not accurate enough. From the descriptions I read, System.Diagnostics.Stopwatch seems to be exactly what I want. But I have a phobia. I'm nervous about using anything from System.Diagnostics in actual production code. (I use it extensively for debugging with Asserts and PrintLns etc, but never yet for production stuff.) I'm not merely trying to use a timer to benchmark my functions - my app needs an actual timer. I've read on another forum that

How to reset a timer in C#?

眉间皱痕 提交于 2019-12-17 15:37:58
问题 There are three Timer classes that I am aware of, System.Threading.Timer , System.Timers.Timer , and System.Windows.Forms.Timer , but none of these have a .Reset() function which would reset the current elapsed time to 0. Is there a BCL class that has this functionality? Is there a non-hack way of doing it? (I thought perhaps changing the time limit on it might reset it) Thought on how hard it would be to reimplement a Timer class that had this functionality, or how to do it reliably with one

Android - Run a thread repeatingly within a timer

拈花ヽ惹草 提交于 2019-12-17 12:47:22
问题 First of all, I could not even chose the method to use, i'm reading for hours now and someone says use 'Handlers', someone says use 'Timer'. Here's what I try to achieve: At preferences, theres a setting(checkbox) which to enable / disable the repeating job. As that checkbox is checked, the timer should start to work and the thread should be executed every x seconds. As checkbox is unchecked, timer should stop. Here's my code: Checking whether if checkbox is checked or not, if checked

C# Timer or Thread.Sleep

别等时光非礼了梦想. 提交于 2019-12-17 10:33:28
问题 I am running a windows service and using a loop and Thread.Sleep to repeat a task, would it be better to use a timer method? If yes a code example would be great I am currently using this code to repeat int curMinute; int lastMinute = DateTime.Now.AddMinutes(-1).Minute; while (condition) { curMinute = DateTime.Now.Minute; if (lastMinute < curMinute) { // do your once-per-minute code here lastMinute = curMinute; } Thread.Sleep(50000); // sleeps for 50 seconds if (error condition that would

How to execute a method periodically from WPF client application using threading or timer [closed]

自闭症网瘾萝莉.ら 提交于 2019-12-17 10:29:26
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 6 years ago . I am developing a WPF client application.This app sends data periodically to the webservice . When user logged into the app I want run particular method every 5 mts to send data to the .asmx service. My question

System.Timers.Timer/Threading.Timer vs Thread with WhileLoop + Thread.Sleep For Periodic Tasks

血红的双手。 提交于 2019-12-17 10:21:48
问题 In my application I have to send periodic heartbeats to a "brother" application. Is this better accomplished with System.Timers.Timer/Threading.Timer or Using a Thread with a while loop and a Thread.Sleep? The heartbeat interval is 1 second. while(!exit) { //do work Thread.Sleep(1000); } or myTimer.Start( () => { //do work }, 1000); //pseudo code (not actual syntax)... 回答1: System.Threading.Timer has my vote. System.Timers.Timer is meant for use in server-based (your code is running as a

PyQt4 - creating a timer

落花浮王杯 提交于 2019-12-17 09:56:39
问题 I'm sorry for the question but I have read a bunch of things and it seems that I do not get how to make a timer. So I'm posting my code: from PyQt4 import QtGui, QtCore from code.pair import Pair from code.breadth_first_search import breadth_first_search import functools class Ghosts(QtGui.QGraphicsPixmapItem): def __init__(self, name): super(Ghosts, self).__init__() self.set_image(name) def chase(self, goal): pos = Pair(self.x(), self.y()) path = breadth_first_search(pos, goal) while not