KeldorKatarn
Topic Author
Posts: 193
Joined: 30 May 2014, 10:26

Equivalent of Application.Current.Dispatcher in Unity?

25 May 2021, 11:00

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.
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Equivalent of Application.Current.Dispatcher in Unity?

25 May 2021, 13:25

You can get it from NoesisView's Content:
NoesisView view = GetComponent<NoesisView>();
return view.Content.Dispatcher;
Would that work for you?
 
KeldorKatarn
Topic Author
Posts: 193
Joined: 30 May 2014, 10:26

Re: Equivalent of Application.Current.Dispatcher in Unity?

25 May 2021, 13:51

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
Topic Author
Posts: 193
Joined: 30 May 2014, 10:26

Re: Equivalent of Application.Current.Dispatcher in Unity?

25 May 2021, 13:55

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?
 
User avatar
sfernandez
Site Admin
Posts: 2991
Joined: 22 Dec 2011, 19:20

Re: Equivalent of Application.Current.Dispatcher in Unity?

25 May 2021, 14:03

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
Topic Author
Posts: 193
Joined: 30 May 2014, 10:26

Re: Equivalent of Application.Current.Dispatcher in Unity?

25 May 2021, 14:27

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.

Who is online

Users browsing this forum: Google [Bot], Semrush [Bot] and 6 guests