- KeldorKatarn
- Posts: 193
- Joined:
Equivalent of Application.Current.Dispatcher in Unity?
Is there any way to get the UI Thread Dispatcher either globally or from a specific NoesisView (should not matter, it's the same thread after all?) from the Noesis API?
I know I can call Dispatcher.CurrentDIspatcher in the UI thread but i'd like to avoid that because I don't want to have to store that kind of state.
I know I can call Dispatcher.CurrentDIspatcher in the UI thread but i'd like to avoid that because I don't want to have to store that kind of state.
-
sfernandez
Site Admin
- Posts: 3152
- Joined:
Re: Equivalent of Application.Current.Dispatcher in Unity?
You can get it from NoesisView's Content:
Would that work for you?
Code: Select all
NoesisView view = GetComponent<NoesisView>();
return view.Content.Dispatcher;
- KeldorKatarn
- Posts: 193
- Joined:
Re: Equivalent of Application.Current.Dispatcher in Unity?
I wanted it in a static context, but I guess I can just do Object.FindObjectOfType to get the NoesisView and then store the dispatcher. FIndObject isn't exactly fast, but once to boot up the framework should be fine.
- KeldorKatarn
- Posts: 193
- Joined:
Re: Equivalent of Application.Current.Dispatcher in Unity?
Come to think of it.... what happens if I store that Dispatcher and then the Camera with the NoesisView component on it is destroyed.
Can I somehow detect that my DIspatcher is now invalid?
Can I somehow detect that my DIspatcher is now invalid?
-
sfernandez
Site Admin
- Posts: 3152
- Joined:
Re: Equivalent of Application.Current.Dispatcher in Unity?
The Dispatchers are created for each thread, so once a Dispatcher is requested for one thread it will stay alive until application is closed. But the dispatchers only process their queue if there is any View being updated in their thread, so they are useless without views.
- KeldorKatarn
- Posts: 193
- Joined:
Re: Equivalent of Application.Current.Dispatcher in Unity?
Well I use it with "Invoke" to invoke certain things on the UI thread. And I just tried making a viewmodel that does endless Debug,Log() calls every 500ms using the Dispatcher to dispatch that to the UI thread.
And it kinda works just fine. The viewmodels keeps logging via the dispatcher even though the entire camera is gone... so the dispatcher still works.
And it kinda works just fine. The viewmodels keeps logging via the dispatcher even though the entire camera is gone... so the dispatcher still works.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests