How to find UI thread in UWP

I am trying to understand how Threading works in UWP.

The knowledge that I have:

1) Each application window will have a user interface thread. And many threads Worker (or Background).

2) User interface elements can only be accessed through the user interface stream. You can do all the intensive memory calculations in background threads and just assign values ​​to the user interface thread to support an adaptive user interface.

To do this, use CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync (() =>) .

3) To check if a thread is a UI thread or a thread without a UI, CoreApplication.MainView.CoreWindow.Dispatcher.HasThreadAccess can be used . (As indicated here

But,

When I try to use CoreApplication.MainView.CoreWindow.Dispatcher.HasThreadAccess, it returns True in most cases. (Even from the category of working lines)

In addition, in the “Debugging in a thread” section of the “Category” column, there is a Main thread that has only one thread, as shown below:

enter image description here

EDIT: My colleague said If Name Worker Thread and then its Non GUI thread.

Observable.Start(From System.Reactive) Task.Run, ( ), . Concept: (

enter image description here

:

One Ui ? .. ? ( 0)

!

+8
1

(2) Run Async ( ). , , .

, - . , Run Async, , . , HasThreadAccess true.

( ), Task.Run. , , , , . (, SemaphoreSlim).

SJB

0

Source: https://habr.com/ru/post/1015234/


All Articles