'Why is this WinRT function required to be extracted while others are not?
At https://docs.microsoft.com/en-us/windows/uwp/launch-resume/handle-app-prelaunch#detect-and-handle-prelaunch it reads:
Note the
TryEnablePrelaunch()
function, above. The reason the call toCoreApplication.EnablePrelaunch()
is factored out into this function is because when a method is called, the JIT (just in time compilation) will attempt to compile the entire method. If your app is running on a version of Windows 10 that doesn't supportCoreApplication.EnablePrelaunch()
, then the JIT will fail. By factoring the call into a method that is only called when the app determines that the platform supportsCoreApplication.EnablePrelaunch()
, we avoid that problem.
Why is this fuss necessary here while it doesn't seem necessary at all other occasions?
Solution 1:[1]
It's outdated guidance from the WinPhone days. It was necessary to break calls into separate methods so you could catch the MissingMethod exception.
Solution 2:[2]
Actually, it is always important to make sure if the API is available on a device. The note in the first document emphasized the reason why you should not use an API that is not available in the current OS version. The second document gives a summary about this and shows the common ways to check API availability.
Both of them are telling the importance of API availability.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Peter Torr - MSFT |
Solution 2 | Roy Li - MSFT |