tags:

views:

32

answers:

1

Presently, I am checking the method name in the OnMethodBoundaryAspect.OnExit method:

[Serializable]
public class TimerAttribute : OnMethodBoundaryAspect
{
    public override void OnExit(MethodExecutionEventArgs eventArgs)
    {
        if(eventArgs.Method.DeclaringType.Name == "Program" && eventArgs.Method.Name == "Main")
            //do things
    }
}

Obviously, this is ugly and feels kludgy. Is there a more robust way to detect application exit with PostSharp?

+1  A: 

I don't think you should use PostSharp to do that.

You can detect whether the application domain is exiting by using some features of System.AppDomain:

  • AppDomain.IsFinalizingForUnload()
  • AppDomain.ProcessExit
  • AppDomain.DomainUnload
Gael Fraiteur
That's definitely true ;)
Alex Yakunin
I would like to implement this in an aspect-oriented manner.
Abtin Forouzandeh