1 / 18

Advanced Windows Prog.

Advanced Windows Prog. Chapter 10 – The Timer and Time Programming Microsoft Windows with C# - Charles Petzold Presented By: Srinivas B. Shilagani. Timer. Timer is an i/p device that periodically notifies an application when a specified interval time has elapsed.

shada
Download Presentation

Advanced Windows Prog.

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Advanced Windows Prog. Chapter 10 – The Timer and Time Programming Microsoft Windows with C# - Charles Petzold Presented By: Srinivas B. Shilagani

  2. Timer • Timer is an i/p device that periodically notifies an application when a specified interval time has elapsed. • The timer triggers an event handler after every specified interval

  3. C# Timers Three classes are defined in • System.Timers • System.Threading • System.Windows.Forms*

  4. Application • Multitasking: It is advisable to return control to windows because of premptive nature of windows. • Maintaining an updated status report. • Implementing an auto save feature. • Animation: Eliminates inconsistencies because of variations in microprocessor speed.

  5. Timer Class • Constructor: Timer timer = new Timer(); • Events Timer.Tick += new EventHandler(TimerOnTick); void TimerOnTick(object obj, EventArgs ea){ … }

  6. Timer Properties Can we always achieve interval granularity? • Windows rounds the interval you specify to the next highest multiple of the period of the OS’s internal clock. • Timer Methods include start() and stop()

  7. DateTime Structure • Namespace: System.DateTime Represents Date and Time in .NET Framework. • Constructors: 7 are available • DateTime(int year, int month, int day) • DateTime(int year, int month, int day, int hour, int minute, int second) • DateTime(int year, int month, int day, int hour, int minute, int second, int msec)

  8. Points to note • Exception is thrown on inconsistency of Date. • Default Calendar used is Gregorian Calendar. • Leap Year is defined as any year divisible by 4 and not by 100 unless it is divisible by 400

  9. DateTime Properties • Most frequently used properties: • Year, Month, Day, Hour, Minute, Second, MilliSecond, DayofWeek, DayofYear, Date • UTC – Coordinated Universal Time • DateTime ToLocalTime() • DateTime ToUniversalTime() • Operators ==, !=, <, >, <=, >=

  10. Static Properties

  11. System.TimeZone • Its an Abstract Class • Static Property :CurrentTimeZone() TimeZone tz=TimeZone.CurrentTimeZone(); How does this work? • Properties

  12. TimeZone Methods • TimeSpan GetUtcOffset(DateTime dt) • DateTime ToLocalTime(DateTime dt) • DateTime ToUniversalTime(DateTime dt) • DaylightTime GetDaylightChanges(int year) • bool IsDaylightSavingTime(DateTime dt) Eg: tz.GetUtcOffset(new DateTime(2002,2,2)) returns –5:00:00. We add this to get EST.

  13. DaylightTime and Ticks • DaylightTime properties • DateTime Start() (April 7 2002 at 2am) • DateTime End() (October 27 2002 2am) • DateTime Delta() • The Tick Count • Number of 100nS since midnight January 1,1 • Constructor: • DateTime(long ticks) • Properties: • long Ticks() – 100nS interval since 1/1/0001. • TimeSpan TimeOfDay() – Ticks since midnight.

  14. TimeSpan • It’s a structure defined in a System namespace that is used to express durations of time in units of 100nS. It represents elapsed time. • Constructor: • TimeSpan(long ticks) • TimeSpan(int hours, int minutes, int seconds) • TimeSpan(int days, int hours, int minutes, int seconds) • It is possible to add Date and TimeSpan.

  15. Calendar • NameSpace: System.Globalization • Calendar is an Abstract class • Constructors • DateTime(int year, int month, int day, Calendar cal) • DateTime(int year, int month, int day, int hr, int min, int sec, Calendar cal) • Methods • int GetYear(DateTime dt) • int GetMonth(DateTime dt) • int GetDayOfMonth(DateTime dt)

  16. Formatting Display • DateTime.ToString(string strFormat, IFormatProvider ifp) • String Formats: series of letters that describe custom formatting. • D - Saturday, June 01, 2002 • f - Saturday, June 01, 2002 4:00 AM • d - Date, f – Full, g – General, m – month/day, t- time, y – year/month.

  17. IFormatProvider • IFormatProvider is an interface. We need a class that represents an instance of a class that implements this interface. Eg: DateTimeFormatInfo • Properties - static • DateTimeFor matInfo CurrentInfo() • DateTimeFormatInfo InvariantInfo()

  18. Other Formatting Methods

More Related