bkunikowski
Topic Author
Posts: 12
Joined: 02 Apr 2025, 12:18

Problem with UI thread (cannot access this Border because a different thread owns it)

09 Sep 2025, 10:02

I'm trying to integrate more and more stuff from Noesis to custom engine. Currently I have problem with threading. My engine uses different workers to initialize and then update many systems. One of them is UI system (Noesis). So due to there are many different threads, Noesis comes with ERROR that cannot access some element due to different thread owns it.

So I created dedicated thread and delegate all Noesis Views creation and updates to this thread, but still have info that my Main Thread owns some stuff.
Could you explain what does it mean that element is own by thread? What else should I do in such case?

Error:
The calling thread (53740) cannot access this Border because a different thread (6184) owns it
 
bkunikowski
Topic Author
Posts: 12
Joined: 02 Apr 2025, 12:18

Re: Problem with UI thread (cannot access this Border because a different thread owns it)

09 Sep 2025, 11:42

Xaml I use to view creation has good thread id. LoadXaml is called just before CreateView function on the same dedicated thread. The error appears when I want to execute view->SetSize(size.x, size.y) function later in some frame stuff scope.
 
bkunikowski
Topic Author
Posts: 12
Joined: 02 Apr 2025, 12:18

Re: Problem with UI thread (cannot access this Border because a different thread owns it)

09 Sep 2025, 12:24

I'm tried with that piece of code executed on my UI thread.
	m_queue->syncTask<void>([this]() {
		Noesis::Ptr<Noesis::FrameworkElement> xaml = Noesis::GUI::LoadXaml<Noesis::FrameworkElement>(m_xamlResource->resourcePath().c_str());
		auto view = Noesis::GUI::CreateView(xaml);
		view->SetSize(1920, 1080);
	});
Explanation:
m_queue is queue with tasks to execute on UI thread.
What interesting I've checked xaml->CheckAccess() and it returns true and xaml->GetThreadId() returns my UI thread ID.

However execution of that piece of code results with the same error as previous on SetSize line

Is view instances always bound to Main Thread? Because it always refer to Main thread as a thread that owns stuff.
 
bkunikowski
Topic Author
Posts: 12
Joined: 02 Apr 2025, 12:18

Re: Problem with UI thread (cannot access this Border because a different thread owns it)

10 Sep 2025, 09:08

Ok, it looks that loading default styles also needs to be done on UI thread. That's the reason.
 
User avatar
jsantos
Site Admin
Posts: 4823
Joined: 20 Jan 2012, 17:18
Contact:

Re: Problem with UI thread (cannot access this Border because a different thread owns it)

10 Sep 2025, 14:24

Sorry for the late reply. As you noticed, the first time an instance is accessed on a thread, it becomes tied to that thread. From then on, every access to that instance must come from the same thread.

If you’re certain that the instance is only being touched by one thread at a time (and there are no concurrent accesses), you can safely ignore the warning. We’re aware this can be inconvenient, especially since many studios run Noesis inside jobs that may execute on different threads each frame. Because of this, we plan to add an option to disable that warning in the future.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests