You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[#MVU] Updating model crashes on net8.0-windows10.0.19041 but works fine on net8.0-desktop #2455
I have created very simple app that presents a list of Items in an ItemsRepeater.
All works fine on net8.0-desktop but on net8.0-windows10.0.19041 the app constantly crashes when MainPageModel.AddItem() method is called.
Note that the App crashes differently cross many executions which suggests some concurrency issue.
Note that another concurrency issue is as well reported in #2349. Maybe both are related?
09:12:57:390 Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Private.CoreLib.dll
09:12:57:390 Exception thrown: 'System.Runtime.InteropServices.COMException' in System.Private.CoreLib.dll
09:13:00:252 Exception thrown: 'System.Runtime.InteropServices.COMException' in WinRT.Runtime.dll
09:13:00:252 An exception of type 'System.Runtime.InteropServices.COMException' occurred in WinRT.Runtime.dll but was not handled in user code
Alright, the problem is that when adding a new Item we are initializing a new SolidColorBrush in GetRandomItem() while we are on the background thread. The Dispatcher will need to be used to run that logic on the UI thread
For further clarity, in MVUX, anything happening in a Command is OFF the UI Thread. If you make a UI update by updating your Model using IState, the State is responsible to make sure (through the generated Bindable Proxy) to go back on the UI Thread.
The rule is to NOT deal with UI elements in a Model (like creating Brushers or others). If needed, you need to make those calls by going back on the UI Thread directly using the IDispatcher.
I would assume (needs testing) that Colors can be created off UI thread but not the Brush directly.
The rule is to NOT deal with UI elements in a Model (like creating Brushers or others). If needed, you need to make those calls by going back on the UI Thread directly using the IDispatcher.
I would agree, @kucint having a proper separation of concerns you should never have UI types in the DataContext regardless of whether you're using MVVM or MVU.
That said as @francoistanguay suggested the Color itself should be fine as it is just a struct.
I would agree, @kucint having a proper separation of concerns you should never have UI types in the DataContext regardless of whether you're using MVVM or MVU.
@dansiegel This is very valid statement, Proper separation of concerns is critical. I took a lesson. Thanks!
Activity
kazo0 commentedon Jul 30, 2024
Alright, the problem is that when adding a new Item we are initializing a new SolidColorBrush in GetRandomItem() while we are on the background thread. The Dispatcher will need to be used to run that logic on the UI thread
francoistanguay commentedon Jul 30, 2024
For further clarity, in MVUX, anything happening in a Command is OFF the UI Thread. If you make a UI update by updating your Model using IState, the State is responsible to make sure (through the generated Bindable Proxy) to go back on the UI Thread.
The rule is to NOT deal with UI elements in a Model (like creating Brushers or others). If needed, you need to make those calls by going back on the UI Thread directly using the IDispatcher.
I would assume (needs testing) that Colors can be created off UI thread but not the Brush directly.
dansiegel commentedon Jul 30, 2024
I would agree, @kucint having a proper separation of concerns you should never have UI types in the DataContext regardless of whether you're using MVVM or MVU.
That said as @francoistanguay suggested the Color itself should be fine as it is just a struct.
kucint commentedon Jul 31, 2024
@dansiegel This is very valid statement, Proper separation of concerns is critical. I took a lesson. Thanks!
kazo0 commentedon Aug 8, 2024
fyi @kucint / @dr1rrb
I will close this issue as the remaining work is tracked as part of #2434 to highlight the UI Thread concerns when dealing with ICommands in MVUX