timer

Text change when background colour changes using Javascript

左心房为你撑大大i 提交于 2019-12-13 09:48:22
问题 Below is my Javascript for changing the background colour of a website, however is there a way to change text in the body of the page when this change in colour occurs? function changeColor(element, curNumber){ curNumber++; if(curNumber > 4){ curNumber = 1; } console.log(curNumber); element.addClass('color' + curNumber, 500); // So previous classes get removed. element.attr('class', 'color' + curNumber); setTimeout(function(){changeColor(element, curNumber)}, 1000); } changeColor($('

Countdown timer for hours, minutes, and seconds

感情迁移 提交于 2019-12-13 09:47:01
问题 How to set cookie for this count down timer? The cookie should prevent resetting timer while I am refreshing the page. <div id="hms">02:00:00</div> <script type="text/javascript"> function count() { var startTime = document.getElementById('hms').innerHTML; var pieces = startTime.split(':'); var time = new Date(); time.setHours(pieces[0]); time.setMinutes(pieces[1]); time.setSeconds(pieces[2]); var timedif = new Date(time.valueOf() - 1000); var newtime = timedif.toTimeString().split(' ')[0];

async/await with thread timer

白昼怎懂夜的黑 提交于 2019-12-13 08:56:23
问题 I was able resolve the issue with the input form Stephen Cleary. Please see update 3. I have a Windows Forms application that has a method with the async modifier. If the method is called inside a button's click event it does not block the UI thread. However, when I call it inside a timer as a callback it freezes the UI. I could not figure out what I am doing wrong here. Please see below my code. This is just a sample project for demonstration purposes. public Form1() { InitializeComponent();

How to stop the Timer thread?

拜拜、爱过 提交于 2019-12-13 08:47:44
问题 How to stop the Timer thread? I have a timer thread and I would like to stop it. How do I do it? I tried to stop by stopping the thread but it was unsuccessful. Any ideas? Thank you in advance for your help this is my code: public void startTimer() { startTime = System.currentTimeMillis(); final Handler handler = new Handler(); task =new Thread() { @Override public void run() { long millis = System.currentTimeMillis()-startTime; long secs = millis / 1000 % 60; // seconds, 0 - 59 long mins =

Using countdown timer to jump out of while loop Python

我怕爱的太早我们不能终老 提交于 2019-12-13 08:47:41
问题 I'll just get to the code to show you, I'm trying to stop my while loop when my timer is over. Is there a way to do that? from threading import Timer def run(timeout=30, runs): timer(timeout) while runs > 0 or over(): #Do something print "start looping" def timer(time): t = Timer(time, over) print "timer started" t.start() def over(): print "returned false" return False As you can see, I'm trying to use the function over() to stop my while loop. Currently, when my time stop, over is returned

Using Dispose() method

好久不见. 提交于 2019-12-13 08:39:04
问题 Why I see "Hello" words many times when I add timer.Dispose() to my code in release mode. Without timer.Dispose() I see "Hello" once. Thanks. using System.Threading; namespace ConsoleApplication1 { class Program { static void Method(object state) { Console.WriteLine(state); GC.Collect(); } static void Main() { var timer = new Timer(Method, "Hello", 0, 200); Console.ReadLine(); timer.Dispose(); } } } 回答1: You see it once because the garbage collector has collected the timer object. Since there

How can i get data without blocking?

﹥>﹥吖頭↗ 提交于 2019-12-13 08:38:37
问题 I have a serial port external device for getting data. I set two timers. One of them has to be for plotting(0.5sn) and the other for writing to a text file(15sn). Timers shouldn't get data from each other by list or array. Because sometimes I need to close plotting button. So I have to get data from the same resource (coming continuous data), right? But when I try this, it blocked. And how to get data without blocking? As an example the below code runs without blocking: # -*- coding: utf-8 -*

file modifiaction and manipulation

北慕城南 提交于 2019-12-13 08:37:59
问题 How would you scan a dir for a text file and read the text file by date modified, print it to screen having the script scan the directory every 5 seconds for a newer file creadted and prints it. Is it possible that you can help me i'm stuck and i need this real bad and i've already got the scan dir for file and print but it does not print the files by date modidfied. import os,sys os.chdir(raw_input('dir_path: ') ) contents=os.listdir('.') #contents of the current directory files =[]

Timer in Java FX [duplicate]

本小妞迷上赌 提交于 2019-12-13 08:35:31
问题 This question already has answers here : How to avoid Not on FX application thread; currentThread = JavaFX Application Thread error? (7 answers) Closed 2 years ago . I have exeption in Timer whith use JavaFX. timer imported of java.util code of timer: @FXML private Label q1lt; private final Timer t1=new Timer(); TimerTask t2=new TimerTask(){ int i = 300000; public void run() { if(i==0){ file(prim+" "+b+"Балів","D://Результат.txt"); t1.cancel(); return; } i--; int h,m,s; h=i/360000; m=i/6000

Keeping Ajax timer synchronised

独自空忆成欢 提交于 2019-12-13 08:32:03
问题 I have the following jQuery function that I'm using to display a timer on a page: function update() { $.ajax({ type: 'POST', url: 'check_time.php', data: 'checktime=true', timeout: 0, success: function(data) { $(".time_remaining").html(data); window.setTimeout(update, 1000); var time = data; if(time<=0) { $(".time_remaining").html("Reloading the page now."); refresh(); } else { $(".time_remaining").html("There are "+data+" seconds left." ); } }, error: function (XMLHttpRequest, textStatus,