Wednesday, 26 September 2012

Skip Over OnTimer_Tick Event C#

Something that was starting to frustrate me when debugging a project was the OnTimer_Tick event that kept taking the focus when stepping through the code. (F11) or (F10). 


But by referencing 


System.Diagnostics 

You can place this tag above the event and it wont step into this event when the code is debugging.

[DebuggerHiddenAttribute]

 As I will demonstrate below.
Code Snippet
  1. #region[Event] – Timer1Tick(xxx,xxx)
  2. ///<summary>
  3. /// When Timer1 ticks.
  4. ///</summary>
  5. ///<param name=”sender”>The sender.</param>
  6. ///<param name=”e”>The <see cref=”System.EventArgs”/> instance containing the event data.</param>
  7. [DebuggerHiddenAttribute]
  8. private void Timer1Tick(object sender,
  9. EventArgs e)
  10. {
  11. // get the current process
  12. long totalBytesOfMemoryUsed;
  13. using (Process currentProcess = Process.GetCurrentProcess())
  14. {
  15. totalBytesOfMemoryUsed = currentProcess.WorkingSet64;
  16. }
  17. toolStripStatusLabel1.Text = string.Format(“Current Memory Usage {0} MB”,
  18. ((totalBytesOfMemoryUsed / 1024) / 1024));
  19. }
  20. #endregion

I just wanted to post this, just in case it helps someone else one day!