Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

How to avoid recursion

By: a guest on Aug 2nd, 2014  |  syntax: C#  |  size: 0.30 KB  |  views: 2,261  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. publiv void RefreshValues()
  2. {
  3.         var stack = new StackTrace(1);
  4.         var frames = stack.GetFrames();
  5.         var m = MethodBase.GetCurrentMethod().Name;
  6.        
  7.         if (frames.Any(f => f.GetMethod().Name == m))
  8.                 return;
  9.  
  10.         // actual code that sets values which in turn might (or might not) call this method again      
  11. }
clone this paste RAW Paste Data