OnExit is invoked before the end of the function happens.
See original GitHub issuehttps://github.com/Fody/MethodDecorator/issues/28
One of the things I’m trying to use this lib for is to figure out the execution time of some methods by running Stopwatch on the Entry/Exit, but what I’ve realised is happening is that due to the OnExit being executed in the try
instead of finally
(I THINK), it results in logs like:
[05:20:57 INF] Invocation of Forward started at 08/11/2020 05:20:57
[05:20:57 INF] Invocation at Forward finished at 08/11/2020 05:20:57 and took 318ms to complete
[05:20:58 INF] Hello World 08/11/2020 05:20:58
So I think issue #28 is still an issue.
This is running on the latest version:
Fody 6.2.0 MethodDecorator 1.1.1 .NET Core 3.1 project (AWS .NET Core Lambda)
public class Banana
{
[HandlerInterceptor]
public async Task<string> DoSomething()
{
var result = await Task.Delay(2000).ContinueWith(x => "Hello World");
if (result == "Hello World")
{
Console.WriteLine("Hello World!");
Console.WriteLine(DateTime.UtcNow);
}
else
{
Console.WriteLine("got nothing...");
Console.WriteLine(DateTime.UtcNow);
}
return result;
}
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Assembly | AttributeTargets.Module)]
[ExcludeFromCodeCoverage]
public class HandlerInterceptorAttribute : Attribute, IMethodDecorator
{
private readonly Stopwatch stopwatch = new Stopwatch();
public void Init(object instance, MethodBase method, object[] args)
{
}
public void OnEntry()
{
stopwatch.Restart();
Console.WriteLine("Start");
Console.WriteLine(DateTime.UtcNow);
}
public void OnExit()
{
stopwatch.Stop();
Console.WriteLine("End");
Console.WriteLine(stopwatch.ElapsedMilliseconds);
}
public void OnException(Exception exception)
{
}
}
}
The output of this is:
Start
8/11/2020 6:11:39 AM
End
0
Hello World!
8/11/2020 6:11:41 AM
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:9 (3 by maintainers)
Top Results From Across the Web
On 'on.exit()'
Introduction. on.exit() is a base R function which records expressions to evaluate when the current function exits.
Read more >How do you run a function on exit in C++
You can use the aptly named std::atexit function in the cstdlib header: ... the exit function is called, or the program returns from...
Read more >Question / feature request: invoking a service onExit from ...
If it's an invoked callback, the "cleanup" function is called. If it's an observable, it is unsubscribed. If it's a machine, it is...
Read more >Calling A Function On Scene Exit?
OnDestroy() can be used to call your Save function before scene change. ... OnDestroy occurs when a Scene or game ends. Stopping the...
Read more >onExit/onAbort
void onAbort(); called whenever a script terminates prematurely, either because the user said to stop, the script said to abort, or a runtime...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
https://github.com/Fody/MethodDecorator/pull/271
I actually had a fix for this bug that I wanted to submit after this but that was 2 years ago.
I no longer have that branch as I wiped my laptop and moved away from fody as it seemed there was no traction on getting this fixed.
@NurOrNuLL how about you step up and submit a pull request that fixes this