Count down timer in vb.net -


in following code have timer counts down 5 mins. trying have visual count down timer in lbl in mm:ss example used doesn't work. counts down doesn't update lbl until hits 00:00.

the asker of following question (were got code) said works me doesn't @ all.

the example used

my code:

private sub form1_load(sender system.object, e system.eventargs) handles mybase.load      piclogo.sizemode = pictureboxsizemode.stretchimage      'timer until update     tmrupdate.interval = 300000 '5 minutes     targetdt = datetime.now.add(countdownfrom)     tmrupdate.enabled = true   end sub  private sub tmrupdate_tick(sender object, e eventargs) handles tmrupdate.tick     dim ts timespan = targetdt.subtract(datetime.now)     if ts.totalmilliseconds > 0         lbltimer.text = ts.tostring("mm\:ss")     else         lbltimer.text = "00:00"         tmrupdate.stop()     end if    end sub 

answer:

using async sub had count down timer running while other stuff going on in ground. way app still used during sub wait() , code displayed count down timer. used 1 timer on 1 sec interval.

private async sub dostuff()  'doing stuff  timeupdate = 599         tmrupdate.start()         application.doevents()         await task.run(sub()                            wait()                         end sub)     loop end sub  private sub timer1_tick(sender object, e eventargs) handles tmrupdate.tick     dim hms = timespan.fromseconds(timeupdate)     dim m = hms.minutes.tostring     dim s = hms.seconds.tostring      if timeupdate > 0         timeupdate -= 1         lbltimer.text = (m & ":" & s)      else          tmrupdate.stop()         lbltimer.text = "text"      end if  end sub  private sub wait()     threading.thread.sleep(600000) end sub 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -