timer

How to get an accurate 1ms Timer Tick under WinXP

旧巷老猫 提交于 2019-12-29 06:47:28
问题 I try to call a function every 1 ms. The problem is, I like to do this with windows. So I tried the multimediatimer API. Multimediatimer API Source idTimer = timeSetEvent( 1, 0, TimerProc, 0, TIME_PERIODIC|TIME_CALLBACK_FUNCTION ); My result was that most of the time the 1 ms was ok, but sometimes I get the double period. See the little bump at around 1.95ms multimediatimerHistogram http://www.freeimagehosting.net/uploads/8b78f2fa6d.png My first thought was that maybe my method was running

Waiting for a Timer to finish in Java

流过昼夜 提交于 2019-12-29 06:06:46
问题 I'm using java.util.Timer to schedule a periodic task. At one point, I'd like to shut it down, and wait for it to finish . Timer.cancel() will prevent any future tasks from running. How do I make sure any tasks are not running at the moment (or wait for them if they are?) I can introduce external synchronization mechanisms, but I don't see how they can cover all cases. For example, if I synchronize on some Monitor within the task, I still miss the case when the task just started executing but

Waiting for a Timer to finish in Java

一曲冷凌霜 提交于 2019-12-29 06:04:07
问题 I'm using java.util.Timer to schedule a periodic task. At one point, I'd like to shut it down, and wait for it to finish . Timer.cancel() will prevent any future tasks from running. How do I make sure any tasks are not running at the moment (or wait for them if they are?) I can introduce external synchronization mechanisms, but I don't see how they can cover all cases. For example, if I synchronize on some Monitor within the task, I still miss the case when the task just started executing but

Thread-safety of System.Timers.Timer vs System.Threading.Timer

风流意气都作罢 提交于 2019-12-29 03:54:08
问题 In this article: http://msdn.microsoft.com/en-us/magazine/cc164015.aspx the author states that System.Threading.Timer is not thread-safe . Since then this has been repeated on blogs, in Richter's book "CLR via C#", on SO, but this is never justified. Moreover the MSDN documentation assures "This type is thread safe." 1) Who tells the truth? 2) If this is the original article what makes System.Threading.Timer not thread-safe and how its wrapper System.Timers.Timer achieves more thread-safety?

How do I make this java for loop pause for 1/2 a second between each iteration?

人走茶凉 提交于 2019-12-29 02:09:12
问题 private class MultipleGensListener implements ActionListener { public void actionPerformed(ActionEvent e) { for(int i = 0; i < 25; i++) { game.runSimulationOneGen(); changeGrid(); } } } //this is the loop. The changeGrid method displays a game grid on a GUI but // only the 25th iteration is visible on screen. I would like each one to be // visible for about a half a second before the loop continues. // I have seen some questions answered on here that are very close to what I'm asking, // but

Do .NET Timers Run Asynchronously?

帅比萌擦擦* 提交于 2019-12-28 11:54:51
问题 I have a messaging aspect of my application using Jabber-net (an XMPP library.) What I would like to do, if for some reason the connection to the Server is ended, is keep trying to connect every minute or so. If I start a Timer to wait for a period of time before the next attempt, does that timer run asynchronously and the resulting Tick event join the main thread, or would I need to start my own thread and start the timer from within there? 回答1: What kind of timer are you using? System

Swift 3 - How to make timer work in background

本小妞迷上赌 提交于 2019-12-28 06:01:11
问题 i am trying to do an application which can make a timer run in background. here's my code: let taskManager = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(self.scheduleNotification), userInfo: nil, repeats: true) RunLoop.main.add(taskManager, forMode: RunLoopMode.commonModes) above code will perform a function that will invoke a local notification. this works when the app is in foreground, how can i make it work in the background? i tried to put several print lines

Swift 3 - How to make timer work in background

跟風遠走 提交于 2019-12-28 06:01:02
问题 i am trying to do an application which can make a timer run in background. here's my code: let taskManager = Timer.scheduledTimer(timeInterval: 10, target: self, selector: #selector(self.scheduleNotification), userInfo: nil, repeats: true) RunLoop.main.add(taskManager, forMode: RunLoopMode.commonModes) above code will perform a function that will invoke a local notification. this works when the app is in foreground, how can i make it work in the background? i tried to put several print lines

Android: How do I display an updating clock in a TextView

荒凉一梦 提交于 2019-12-28 05:10:11
问题 have a clock I want to display in a TextView. I would have thought there was a few nice functions to do this, but I couldn't find anything. I ended up implementing my own way that uses a Handler. What I'm asking though, is there a better (more efficient) way to display a real time updating clock? private Runnable mUpdateClockTask = new Runnable() { public void run() { setTime(); mClockHandler.postDelayed(this, 1000); } }; That's my handler, which runs every second, and then my set time and

How to start an activity after certain time period?

风流意气都作罢 提交于 2019-12-28 04:13:26
问题 i need to start an activity from the current activity after a certain time period. I coded like below. public class FirstActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_first); new Timer().schedule(new TimerTask(){ public void run() { startActivity(new Intent(FirstActivity.this, SecondActivity.class)); } }, 2000); } But its not working..it keeps on crashing.. Is my method correct? my