IsFirstInstance problem since update to 1.1.0.0

Nov 17, 2014 at 8:17 AM
Edited Nov 17, 2014 at 9:25 AM
I have a problem since I updated to 1.1.0.0 from 1.0.2.1 when call IsFirstInstance in the Application.OnExit event of my WPF app.

My code was something like this:
protected override void OnExit(object sender, EventArgs e)
{
    var app =  Application as InstanceAwareApplication;
    if ((app != null && app.IsFirstInstance))
    {
        // Do something
    }
}
and I changed it so it works with the updated package as follows:
protected override void OnExit(object sender, EventArgs e)
{
    var app =  Application as InstanceAwareApplication;
    if ((app != null && app.IsFirstInstance.GetValueOrDefault()))
    {
        // Do something
    }
}
My problem is that now IsFirstInstance is always null when handling the OnExit event, so the code in the if block doesn't execute.

I changed the package dependency to the older version and it still works OK.

I also make that exact call in the OnStartup event handler and it works OK with the updated package, where the IsFirstInstance property always has a true or false value. Code below:
protected override void OnStartup(object sender, StartupEventArgs e)
{
    var app = Application as InstanceAwareApplication;
    if (!(app == null || app.IsFirstInstance.GetValueOrDefault()))
        app.Shutdown();
    else
    {
        // Do something...
    }
}
I'm probably missing something, so any info on this would be welcome. :)

Regards,
Theofanis

Edit: I forgot to mention that this is a WPF app using Caliburn.Micro and a bootstrapper. App.xaml doesn't have a code behind, initialization is handled in the bootstrapper class.
Coordinator
Nov 17, 2014 at 11:07 AM
Thanks for pointing out the issue! I just pushed a new version (both here and on NuGet) with a proper fix.
The problem was caused by the fact that communication objects where relinquished before OnExit was called (hence, isFirstIntance was always null).
Thanks again for reporting this issue, let me know if everything is working again! :)
Nov 17, 2014 at 11:09 AM
Edited Nov 17, 2014 at 11:18 AM
Just when I pushed my changes to my remote with a revert to the older version.

I will check it and report back.

Thanks for the fast reply and action :D

Edit: Works as advertised! :D