Advertisement
Guest User

How to avoid recursion

a guest
Aug 2nd, 2014
2,674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.30 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement