-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
InvalidOperationException when multiple UI threads are used #263
Comments
Hi there and welcome to this repository! A maintainer will be with you shortly, but first and foremost I would like to thank you for taking the time to report this issue. Quality is of the highest priority for us, and we would never release anything with known defects. We aim to do our best but unfortunately you are here because you encountered something we didn't expect. Lets see if we can figure out what went wrong and provide a remedy for it. |
Actually, the simplest course of action would be to make the |
Hi and sorry for late response, I'll look into the problem. |
@FantasticFiasco if you are interested, I do have a working solution that is thread safe. I could create a PR for that if you want |
@HeedfulCrayon I think that would be better than adding changes to the public API. Do you have any code snippets we could add as tests making sure that this functionality doesn't regress with new versions? |
I'd happily collaborate with you on it. Tell me what you want to do and I'll do the other parts. We can work on a branch in your fork? |
I did update the tests in my thread safe version, and all the tests seem to be passing. As for creating a multithreaded test to verify that it is working in a multithreaded scenario, I couldn't figure out how to do that. I will hopefully get a branch on my fork up in an hour or two |
Don't haste, I won't be able to make contributions for a day or so. |
Sorry, relatively new to open source collaboration. I forgot to remove some extra stuff I was using for debugging. My fork should demonstrate the fix. It also shouldn't break any existing unit tests |
np! I'll look into the changes. Do you have a small snippet or sample application that would demonstrate your setup with multiple STA threads? I'll look into whether we will test this using unit tests or automated UI tests. |
I can't really provide a snippet or sample, but the idea is this. Imagine a traditional MVVM application, and in the ViewModel you create a new thread, set it's apartment state to STA and that thread launches a new window. Now both windows have separate UI threads. The reason behind it is there is a Control Center that launches child windows. You can launch multiple child windows that should all have their own UI threads. |
I have an idea for testing the threading aspect. I will have it up soon |
I like your test! I'm looking into building a sample showcasing the support for different STA threads. |
Could you please open up a new pull request from the |
Looks like there is one test failure. I will see if I can solve that issue |
Got it fixed. I needed to use the View's HashCode instead of the View Id since the ViewWrapper generates a new Id every time |
Fixes #263 --------- Co-authored-by: i28423 <[email protected]> Co-authored-by: FantasticFiasco <[email protected]>
Describe the bug
When using multiple STA threads in an application (Main window that launches a child window in a new STA thread), the DialogService registers the views from multiple threads correctly. When accessing the views to find the owner, the application will crash with an InvalidOperationException stating "The calling thread cannot access this object because a different thread owns it"
To Reproduce
Steps to reproduce the behavior:
Expected behavior
The views should be registered in a threadsafe collection, and have checks so that the views that the DialogService is trying to find the owner for are only related to the current thread calling it.
Screenshots
Desktop (please complete the following information):
Additional context
I have implemented a fix using a ConcurrentDictionary collection. I will reference this issue in that PR, but I would love any feedback you may have on it.
The text was updated successfully, but these errors were encountered: