jspuij / Cortex.Net

State management like MobX for .NET and Blazor

Home Page:https://jspuij.github.io/Cortex.Net.Docs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Updating state from a background thread

ante-maric opened this issue · comments

I have found this awesome library couple of days ago and I am just trying it out. I need some help.

In my Blazor server app, I have an observable object that is injected into a component. Some service holds the reference to the same observable. If that service updates observable object, changes are not reflected, component is not re-rendered. Same code re-renders the component if run from within component. I am aware that updates to an observable needs to happen on the UI thread (during debugging of Cortex.Net I figured exception (The current thread is not associated with the Dispatcher. Use InvokeAsync() to switch execution to the Dispatcher when triggering rendering or component state.) is thrown so component is never notified to re-render), but how can you achieve that from background thread outside of a component? I have no access to a Dispatcher so I can't call InvokeAsync.

Maybe I have completely missed the point and maybe I am misusing the library, but in general I am interested how Cortex.Net can be used in Blazor Server app to show some live data on the page by updating it from background thread.