Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

Evaluate throwing if Window is null on UWP #510

Closed
2 tasks done
jamesmontemagno opened this issue Sep 18, 2018 · 9 comments
Closed
2 tasks done

Evaluate throwing if Window is null on UWP #510

jamesmontemagno opened this issue Sep 18, 2018 · 9 comments
Assignees
Milestone

Comments

@jamesmontemagno
Copy link
Collaborator

jamesmontemagno commented Sep 18, 2018

Should we be throwing here?

  • Check if there is a main window, if not run on current thread
  • Audit usage of any Platform main thread usage and change to shared
@Redth
Copy link
Member

Redth commented Nov 5, 2018

We should instead check if there IS a main window, and if there isn't we are already on the 'main' thread and can just execute on the current thread.

@Redth Redth added this to the 1.0.0 milestone Nov 5, 2018
mattleibow added a commit that referenced this issue Nov 7, 2018
GH-510: If there is no main window, then there is no UI thread
@tipa
Copy link
Contributor

tipa commented May 29, 2019

It can still crash here:

if (CoreApplication.MainView.CoreWindow == null)

For example, when execute too early, before the main window has been created, for example in the App constructor
image

@jamesmontemagno
Copy link
Collaborator Author

Do you want to do a PR? or do you want me to?

@tipa
Copy link
Contributor

tipa commented May 30, 2019

I am failing to get the project running without errors on my machine :(
What I would do is wrap line 16 in a try-catch and return true if the InvalidOperationException is thrown

@jamesmontemagno
Copy link
Collaborator Author

No worries (We recommend VS 2017 as there is a regression on VS 2019 16.1 right now for the multi-targeting stuff we are using). I put in a PR #803 to fix it up.

@tipa
Copy link
Contributor

tipa commented Nov 23, 2019

I think if the issue hasn't been fixed with your PR, as the InvalidOperationException can still be thrown, which happens when you access the MainView property before it has been created (try call MainThread.BeginInvokeOnMainThread(action) in your apps constructor to reproduce)

@tipa
Copy link
Contributor

tipa commented Dec 12, 2019

@jamesmontemagno should I open a new issue regarding this problem?

@jamesmontemagno
Copy link
Collaborator Author

It should never throw as we always call IsMainThread and if CoreWindow is null then we return true so it should just fire.

If you can open with a repro that would be good. Or send down a PR :)

@tipa
Copy link
Contributor

tipa commented Dec 13, 2019

Opened a new issue here: #1020

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

No branches or pull requests

4 participants