Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if current application is not null in FocusElementManager Curre… #33

Merged

Conversation

gpetrou
Copy link

@gpetrou gpetrou commented May 17, 2019

…nt_Exit method

@gpetrou gpetrou force-pushed the FocusElementManagerCurrent_Exit branch from 8899907 to 5ecc217 Compare May 17, 2019 09:16
@Dirkster99
Copy link
Owner

Hi, thanks a lot for the pull request - I'd realy like to merge it into the code and release a new version but I need to better understand what the problem is that we are fixing. I could off course be going off and be doing guess work but I prefer communication :-)

Would you be able to give me a short description for this fix? It would, for example, be enough if you give me a short list of test steps and an expectation to verify how the software behaves with and without your fix.

Thanks Dirk

@Dirkster99
Copy link
Owner

I gather from the links below that you want to improve non-WPF support, like WinForms, correct?

...but if we use AppDomain.CurrentDomain.ProcessExit -= ... I am wondering how much sense this makes if we do not use AppDomain.CurrentDomain.ProcessExit += in other places, as well?

@gpetrou
Copy link
Author

gpetrou commented May 22, 2019

Sorry, I should have added a description here as well.
I was seeing an exception here on a WPF application because Exit was called and Application.Current was already null.
I will set it to draft for now as I need to have another look at this in case I missed something. Perhaps just having a null check should be enough.

@gpetrou gpetrou changed the title Check if current application is not null in FocusElementManager Curre… [WIP] Check if current application is not null in FocusElementManager Curre… May 22, 2019
@Dirkster99
Copy link
Owner

OK, if you see Application.Current == null on shutdown we should definitely fix this. I just never saw this problem and did not know its possible until I searched the net today.

I am just not sure about the AppDomain bit

  • I think we should make the detach eventing consistent with the attaching bit (unless I am missing something)

So, we could either do the change below (and leave AppDomain to some other point in time) or also attach an AppDomain Exit event in SetupFocusManagement. (I hope I get this right since I have not used App.Domain so far):

private static void Current_Exit( object sender, EventArgs e )
{
      if (Application.Current != null)
         Application.Current.Exit -= Current_Exit;

      if( _windowHandler != null )
      {
        _windowHandler.FocusChanged -= new EventHandler<FocusChangeEventArgs>( WindowFocusChanging );
        //_windowHandler.Activate -= new EventHandler<WindowActivateEventArgs>(WindowActivating);
        _windowHandler.Detach();
        _windowHandler = null;
      }
}

@gpetrou gpetrou force-pushed the FocusElementManagerCurrent_Exit branch from 5ecc217 to e3fd8b0 Compare May 22, 2019 16:05
@gpetrou gpetrou changed the title [WIP] Check if current application is not null in FocusElementManager Curre… Check if current application is not null in FocusElementManager Curre… May 22, 2019
@gpetrou gpetrou force-pushed the FocusElementManagerCurrent_Exit branch from e3fd8b0 to cb1c51a Compare May 22, 2019 16:07
@gpetrou
Copy link
Author

gpetrou commented May 22, 2019

I took another look at this and I only used a null check for now which seems enough.
Note that the problem does not always happen for me, but when it does the null check seems enough to fix it.

@Dirkster99 Dirkster99 merged commit 55854a3 into Dirkster99:master May 22, 2019
@Dirkster99
Copy link
Owner

This will be in the next release version 3.5.6 (most likely this weekend just because I don't want to build another release every day) but you could get the binaries from CI should you need it more urgent.

OK, thanks for your time and explaining it - I should have seen the point in the other PR (dah...) but I just hate to guess around critical fixes :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants