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

Add static ctor to DispatcherImpl to force late initialization of static UiThread property #2

Merged
merged 2 commits into from
Sep 3, 2021
Merged

Add static ctor to DispatcherImpl to force late initialization of static UiThread property #2

merged 2 commits into from
Sep 3, 2021

Conversation

DrunkyBard
Copy link
Collaborator

Win32Platform.Initialize method contains registration of Windows related components. It also includes registration of IDispatcherImpl that uses DispatcherImpl.UIThread as an instance.

DispatcherImpl.UIThread property retrieves IPlatformThreadingInterface by invoke of AvaloniaLocator.

The thing is that DispatcherImpl.UIThread doesn't have static constructor - it leads to the case when static property might be initialized before Win32Platform.Initialize method call. Such premature initialization raises the error because AvaloniaLocator returns null for IPlatformThreadingInterface.

Adding static constructor to DispatcherImpl forces JIT to generate the code that initializes static property at the moment of property invocation.

@DrunkyBard DrunkyBard merged commit f031cb9 into JetBrains:avalonia-win Sep 3, 2021
@@ -109,7 +109,7 @@ public static void Initialize(Win32PlatformOptions options, IDispatcherImpl cust
.Bind<IKeyboardDevice>().ToConstant(WindowsKeyboardDevice.Instance)
.Bind<IPlatformSettings>().ToConstant(s_instance)
.Bind<IPlatformThreadingInterface>().ToConstant(s_instance)
.Bind<IDispatcherImpl>().ToConstant(customDispatcher ?? DispatcherImpl.UIThread)
.Bind<IDispatcherImpl>().ToConstant(customDispatcher ?? new DispatcherImpl(AvaloniaLocator.Current.GetService<IPlatformThreadingInterface>()))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just use s_instance instead of AvaloniaLocator.Current.GetService<IPlatformThreadingInterface>()?

Copy link
Collaborator Author

@DrunkyBard DrunkyBard Sep 6, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, my bad, it can be replaced to static instance. Here is the update #4

HermanKirshin pushed a commit that referenced this pull request Feb 2, 2022
…ut-keydown-handed-2

win32: Don't raise TextInput event when KeyDown was handled (Attempt #2)
DrunkyBard pushed a commit that referenced this pull request Mar 7, 2022
…ut-keydown-handed-2

win32: Don't raise TextInput event when KeyDown was handled (Attempt #2)
HermanKirshin pushed a commit that referenced this pull request Jul 3, 2023
…latform-interface

Cleanup runtime platform classes #2
HermanKirshin pushed a commit that referenced this pull request Sep 16, 2024
* Add accessibility ID to the TrayPopupRoot on Windows

* [Windows] Add left click and menu item click e2e tests for TrayIcon

* [Windows] Add TrayIcon visibility toggle tests

* Implement macOS tray icon tests

* Make it easier to read tray icon logs

* Try to handle win10 accessibility names

* Try to upload PageSource

* Set condition: always

* Hopefully, it works on CI

* Try to upload PageSource #2

* Fix win10, hopefully for the last time
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