Since you want to identify a certain point in time (and not a display time) you should use UTC instead of local time. When using DateTime.Now instead of DateTime.UtcNow it will also break when switching from/to daylight saving or changing the timezone. ![]() One issue that remains with this code is that it will not work correctly if the system clock changes. Note that we’re writing the HTML in JavaScript and injecting into the DOM by. We will add an svg with a circle element inside to draw a timer ring that will indicate the passing time and add a span to show the remaining time value. Let’s start with creating a basic template for our timer. In the timer handler you write: TimeSpan remainingTime=endTime-DateTime.UtcNow įor other formatting options see Standard TimeSpan Format Strings. Step 1: Start with the basic markup and styles. Var start = DateTime.UtcNow // Use UtcNow instead of NowĮndTime = start.AddMinutes(minutes) //endTime is a member, not a local variable To start the countdown: var minutes = 3 //countdown time If you have C# 5 or the async CTP you probably can write code very similar to what you did, since you then get a continuation based equivalent of Thread.Sleep that doesn't block the UI. ![]() Thread.Sleep on the UI thread blocks the UI, and using it on another thread leads to additional complexity due to thread synchronization.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |