timer

How can I perform a short delay in C# without using sleep?

自古美人都是妖i 提交于 2019-12-17 18:16:46
问题 I'm incredibly new to programming, and I've been learning well enough so far, I think, but I still can't get a grasp around the idea of making a delay the way I want. What I'm working on is a sort of test "game" thingy using a Windows forms application that involves a combat system. In it, I want to make an NPC that does an action every couple of seconds. The problem is, I also want to allow the player to interact between attacks. Thread.sleep really doesn't seem to work for me not only

Reschedule timer in android

大憨熊 提交于 2019-12-17 17:57:09
问题 How can I reschedule a timer. I have tried to cancel the timer/timertask and and schedule it again using a method. But its showing an exception error: Exception errorjava.lang.IllegalStateException: TimerTask is scheduled already Code I have used it : private Timer timer = new Timer("alertTimer",true); public void reScheduleTimer(int duration) { timer.cancel(); timer.schedule(timerTask, 1000L, duration * 1000L); } 回答1: If you see the documentation on Timer.cancel() you'll see this: "Cancels

C# run a thread every X minutes, but only if that thread is not running already

喜欢而已 提交于 2019-12-17 17:25:42
问题 I have a C# program that needs to dispatch a thread every X minutes, but only if the previously dispatched thread (from X minutes) ago is not currently still running . A plain old Timer alone will not work (because it dispatches an event every X minutes regardless or whether or not the previously dispatched process has finished yet). The process that's going to get dispatched varies wildly in the time it takes to perform it's task - sometimes it might take a second, sometimes it might take

Java Label Timer and Saving

孤者浪人 提交于 2019-12-17 17:23:24
问题 Let me explain what I am trying to do. I have two classes extending JFrame , the StartJFrame and TestingJFrame . In the main method, I start up a StartJFrame . It has a single button, start. When that is pressed, I have it set up to hide that frame and start up the TestingJFrame . Right now I don't have anything in the T estingJFrame . In that screen, I want to have a label in the bottom right corner that is a timer, starting on 45 seconds and counting down to 0. I also need to have some code

Timer using frameRate and frame counter reliable?

丶灬走出姿态 提交于 2019-12-17 17:23:00
问题 I'm using p5js to program an animation with a timer countdown. I set my timer up to be updated each frame within an object that is being animated by the draw() function in sketch. Because of this, setInterval() will not work for what I'm trying to do. I thought I could use the frameRate and a frame counter to decide if a second has passed: this.updateTimer = function(){ this.framecounter++; if(this.framecounter > frameRate()){ this.framecounter = 0; //increment seconds } } Is this reliable? I

Can I create a 'set /p “”=' command with a timer in Cmd?

怎甘沉沦 提交于 2019-12-17 16:55:06
问题 I want to create a timer for the 'set /p ""=' command so that if you don't input something in the required time space it moves to a different label. Eg. echo You have 3 seconds to type 'go' (??if not typed in 3 seconds goto fail??) set /p input= if %input%==go goto win goto fail Is it possible to command the program to set a 3 second timer before the 'set /p'? Without mixing it with another language like C# etc? 回答1: Squashman's suggestion is the best one that comes to mind for me as well.

How to make countdown timer not reset when refresh the browser?

匆匆过客 提交于 2019-12-17 16:53:41
问题 When i refresh the browser, the timer resets, so how to make it not reset? This is my code. Please check it. <?php echo $waktune; ?> // You can change it into seconds var detik = <?php echo $waktune; ?>; if (document.images) { parselimit = detik } function begintimer() { if (!document.images) return if (parselimit < 12) { document.getElementById("servertime").style.color = "Green"; } if (parselimit == 1) { document.getElementById("hasil").submit(); } else { parselimit -= 1 curmin = Math.floor

AudioPlayerAgent, timer and webservice

巧了我就是萌 提交于 2019-12-17 16:51:41
问题 my application read a shoutcast. The meta data of the music played is collected from a webservice that return me a Json (so i don't have to decode the stream). I call the webservice every 20 seconds with a timer, this works in my application, but doesn't works in the AudioPlayer.cs //Timer private DispatcherTimer timer; /// <remarks> /// AudioPlayer instances can share the same process. /// Static fields can be used to share state between AudioPlayer instances /// or to communicate with the

Where is timer in a Windows store app?

时间秒杀一切 提交于 2019-12-17 16:33:42
问题 I could not find the Timer when developing a Windows Store App in c#. What is the alternative /new name/way of use of it? 回答1: Different timers for different needs. Roughly... DispatcherTimer - When you want work to be executed on the UI thread . ThreadPoolTimer - When you want work to be executed on a background thread . 回答2: DispatcherTimer is what you are looking for var timer = new DispatcherTimer(); timer.Tick += DispatcherTimerEventHandler; timer.Interval = new TimeSpan(0,0,0,1); timer

Android regular task (cronjob equivalent)

倾然丶 夕夏残阳落幕 提交于 2019-12-17 16:19:58
问题 The last time this question was asked (by a different user), the answer response was: If this is in a running activity, you could use Timer/TimerTask and a Handler, or you could use postDelayed() and an AsyncTask. Here: Android Repetitive Task I am still learning how to program android. I have gone through the skills I do know including threads and had many issues with my code. Can anyone give an example of how to use: time/timertask and handler OR postDelayed() and AsyncTask. Thanks in