I want to prevent re-installation for a large set of methods.
for one method, this code works:
bool _isInMyMethod; void MyMethod() { if (_isInMethod) throw new ReentrancyException(); _isInMethod = true; try { ...do something... } finally { _isInMethod = false; } }
It is tiring to do this for each method.
Therefore, I used the StackTrace class:
public static void ThrowIfReentrant() { var stackTrace = new StackTrace(false); var frames = stackTrace.GetFrames(); var callingMethod = frames[1].GetMethod(); if (frames.Skip(2).Any( frame => EqualityComparer<MethodBase>.Default.Equals(callingMethod,frame.GetMethod()))) throw new ReentrancyException(); }
It works great, but looks more like a hack.
Is there a special API in the .NET Framework for detecting redeployment?
source share