D
Danny Liberty
Hi,
I would like to be able to execute code when a function exits. In c++ I
would have created an object on the stack in the function entry point
and it's destructor would be called when the function exits as
following:
void func()
{
MyObj obj;
.....
} <- Destructor code of MyObj called here.
I could be more explicit by writing this code in C#:
void func()
{
.....DoSomething...
ExitFunction();
}
But note that as opposed to the C++ code, ExitFunction() is not called
in the case an exception was thrown from func(). I could use the same
code in C#, but since the GC is not determinstic my ExitFunction() code
wouldn't be called in time.
You may ask why I want code to run at the function exit if the
instruction flow hasn't reached the end of the code, but this could be
very useful for building a logging infrastructure where I could show
the flow of function calls in my application.
Any suggestions how this can be solved?
Thanks,
Danny
I would like to be able to execute code when a function exits. In c++ I
would have created an object on the stack in the function entry point
and it's destructor would be called when the function exits as
following:
void func()
{
MyObj obj;
.....
} <- Destructor code of MyObj called here.
I could be more explicit by writing this code in C#:
void func()
{
.....DoSomething...
ExitFunction();
}
But note that as opposed to the C++ code, ExitFunction() is not called
in the case an exception was thrown from func(). I could use the same
code in C#, but since the GC is not determinstic my ExitFunction() code
wouldn't be called in time.
You may ask why I want code to run at the function exit if the
instruction flow hasn't reached the end of the code, but this could be
very useful for building a logging infrastructure where I could show
the flow of function calls in my application.
Any suggestions how this can be solved?
Thanks,
Danny