27417

Timers in a .NET application

I would like to know what kind of timers can be used in a C# application and what are their implications in term of cuncurrency in a multi-threaded environment. Could you explain me or link me to an esaustive tutorial? Thank you.

Answer1:

There are two forms of timers - ones that are message based, and typically UI centric, and ones that are thread-based.

The UI versions are the Timer class from Windows Forms or the DispatcherTimer in WPF. These tend to report timings (normally) on the UI thread, and basically use the standard message pump to handle timing.

The System.Timers.Timer and System.Threading.Timer classes use a separate thread for handling timers. These work very well, but the "Tick" events happen on a separate thread. This means you need to handle thread synchronization or UI threading synchronization if you use these.

Recommend

  • Country, city, state, Post code table design
  • Can this technology stack scale? [closed]
  • How to create a for loop in R? [duplicate]
  • Maven - which projects or techologies you are using it for?
  • NSTimer and updating UI
  • GDB skips over my code!
  • Sum and Average of a series of numbers inputed to a text field
  • In a MEAN stack, how can I do one-time MongoDB indexing?
  • Python PIL remove sections of an image based on its colour
  • Spring MVC redirect with custom http headers
  • iOS - Is this a task for enums?
  • Consuming a web service with the Netbeans Platform
  • DataGridView: Pass by Value or Reference?
  • Receive mouse move even cursor is outside control
  • Faster Way To Simultaneously Iterate Over Rolling Window Of Two Or More Numpy Arrays?
  • Can someone please explain to me in the most layman terms how to use EventArgs?
  • how to upload multiple files in c# windows application
  • How to handle images sent by a mobile device?
  • Use of this Javascript
  • C++ Partial template specialization - design simplification
  • NHibernate Validation Localization with S#arp Architecture
  • Control modification in presentation layer
  • Xamarin Forms - UWP Fonts
  • How can I send an e-mail from a vbs script
  • Change JButton Shape while respecting Look And Feel
  • Accessing IRQ description array within a module and displaying action names
  • Sony Xperia Z Tablet not found by adb
  • recyclerView does not call the onBindViewHolder when scroll in the view
  • Javascript convert timezone issue
  • Why is the timeout on a windows udp receive socket always 500ms longer than set by SO_RCVTIMEO?
  • jQuery tmpl and DataLink beta
  • How to get next/previous record number?
  • Cannot Parse HTML Data Using Android / JSOUP
  • Python: how to group similar lists together in a list of lists?
  • How do you join a server to an Active Directory (domain)?
  • Getting Messege Twice Using IMvxMessenger
  • Java static initializers and reflection
  • unknown Exception android
  • Observable and ngFor in Angular 2
  • Unable to use reactive element in my shiny app