SHARE
TWEET

How to avoid recursion

a guest Aug 2nd, 2014 2,531 Never
  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. }
RAW Paste Data
Top