Perhaps a custom class is created that marks the scope of the function? Create an instance of the class at the beginning of the function and when the function exits the class, it goes out of scope and the destructor is called.
The sign of the constructor and destructor is the beginning and end of the function.
Edit: As noted, this does not mean that the destructor is called immediately after the object goes out of scope. It is better to use the using() block:
public void SomeMethod() { using (TraceMethod trace = new TraceMethod()) { } } public class TraceMethod : IDisposable { public TraceMethod() { StartTrace(); }
Stefan
source share