Comments (9)
Hi, you seem to be attempting to set the property of a UI element inside a task, the task is most likely crashing causing the Command to post to it's Error subscription, therefore all other subscriptions will not complete.
By setting RxApp.MainThreadScheduler = Scheduler.CurrentThread;
you are setting the UI thread to what could be a random thread as it will be whatever thread is executing the constructor, it's possible that this is not the correct UI thread.
Setting of UI components should be done through properties in the ViewModel and bindings in the View, I believe that your doing this, however the binding uses the RxApp.MainThreadScheduler
thread and you have manipulated this to be a random thread instead of the Pre defined UI thread for WPF. This will cause the Binding to fail also therefore the UI status will not be updated as the underlying function has crashed.
Currently ReactiveCommand.CreateFromTask does not guarantee that errors will be posted when they occur, when they do it's quite random as to whether or not the Task will return any result, hence the issue occurs, making sure you put error handlers inside of the execution code will help to ensure errors are handled better.
Subscribing to the Errors of each ReactiveCommand will help you to see why the command may not be returning the completed status.
Hopefully this helps you to understand some of the issues that are occurring in your code.
from reactiveui.
Thank you for the quick replay.
You say this RxApp.MainThreadScheduler = Scheduler.CurrentThread
could be any Thread, but with this the code works (the command sets the VM values correctly and therefore the UI, apart from the enabled); without it, the app breaks immediately as soon as I click the button, with the cross-Thread Exception I described, without even touching the UI or setting any value.
What is the correct way to set RxApp.MainThreadScheduler
? In the App.xaml.cs
? Somewhere else?
The default value is an instance of System.Reactive.Concurrency.DefaultScheduler,
which is not working.
from reactiveui.
Also, if I add this line:
Increment.ThrownExceptions.Subscribe(x => Debug.WriteLine($"ThrownExceptions? {x}"));
Nothing happens, the Observable never notifies exceptions.
from reactiveui.
Increment = ReactiveCommand.CreateFromTask(async () => {
await Task.Delay(1000);
Content = "Changed";
});
The Content = "Changed"
would be happening on a non-UI thread. The subscribe is run on the UI thread but the Task part is not deliberately.
You can feed results from your CreateFromTask to your main UI thread.
See the docs how.
from reactiveui.
"The Content = "Changed" would be happening on a non-UI thread.".
This does not matter. The WPF binding is thread-safe: you can change a property from another thread, the UI update is always triggered on the Main Thread.
Actually the solution was to switch package: from ReactiveUI
to ReactiveUI.WPF.
There is a warning telling that that library is for .NET 4.6.1 (or similar), but it works as a charm.
No need to set RxApp.MainThreadScheduler, and the Buttons return active after the execution.
from reactiveui.
it's not, only if you're using wpf binding is it thread safe. If you're setting it direct it won't be.
from reactiveui.
from reactiveui.
"The Content = "Changed" would be happening on a non-UI thread.". This does not matter. The WPF binding is thread-safe: you can change a property from another thread, the UI update is always triggered on the Main Thread.
Actually the solution was to switch package: from
ReactiveUI
toReactiveUI.WPF.
There is a warning telling that that library is for .NET 4.6.1 (or similar), but it works as a charm. No need to set RxApp.MainThreadScheduler, and the Buttons return active after the execution.
You need to set your target to include windows10.0.19041.0 for example net7.0-windows10.0.19041.0 then you will be using the correct ReactiveUI and related libraries.
Sorry I didn't realise you were not using the Wpf package of ReactiveUI with Wpf.
We aim to make the framework ready to use without much configuration for each of the packages available.
from reactiveui.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from reactiveui.
Related Issues (20)
- Make generic IViewFor<TViewModel> implementation optional in favor of non-generic IViewFor HOT 15
- Add overloads for the command binders that accept IViewFor HOT 1
- [Bug]: got imcompatible message when using with .net 7 HOT 2
- [Bug]: Visual Studio hot reload broken HOT 21
- [Bug]: Putting RoutedViewHost inside a TabControl on Avalonia causes an app crash after navigating the second time HOT 7
- [Bug]: `ObservableAsPropertyHelper` emits property changed for lazy initial value after first-time reading and doesn't respect `DistinctUntilChanged` HOT 1
- [Bug]: Mark ReactiveObject IObservable properties with DisplayAttribute for Winforms HOT 9
- ReactiveUI.WPF does not include .net 8.0 as a target: HOT 3
- [Bug]: Unable to use activation of views on Windows with MAUI HOT 2
- ViewModelViewHost: Better to Allow Developers Bypass the Default Fallback Behavior That Resovles View With No Contract HOT 2
- [Bug]: WireUpControls throws exception in net8.0-android HOT 8
- [Bug]: ViewModelViewHost does not set DataContext in WPF HOT 2
- [Bug]: WPF targeting issue for net6.0-windows HOT 4
- Dependency Dashboard
- [Bug]: iOS threading exception on command execution. HOT 4
- Bounce transition duration support HOT 3
- [Bug]: WinUI/WAS - ReactiveUI.WinUi nuget attempts to load the ReactiveUI.XamForms assembly when WhenActivated is called on a IActivatableViewModel HOT 5
- Leverage dependencies available from framework
- [Bug]: Memory leak when using ReactiveValidation
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reactiveui.