Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multi thread error #22

Open
heartacker opened this issue Apr 6, 2023 · 3 comments
Open

multi thread error #22

heartacker opened this issue Apr 6, 2023 · 3 comments

Comments

@heartacker
Copy link

when we use

Task.Run(()=>
{
	A = 10;
});

throw a runtime error

Text="{x:Bind A}"
@levitali
Copy link
Owner

levitali commented Apr 8, 2023

I suppose, setting A property raises PropertyChanged event. So that the value of the property is immediately set to the TextBlock’s Text property.

You can set control's property only in main thread. Updating UI from background thread is not supported in any (known me) UI frameworks.

@heartacker
Copy link
Author

Thanks. And could you please help me or provide a Solution to deal with this problem?

I need to update the binding property in the task /new thread

@levitali
Copy link
Owner

levitali commented Apr 9, 2023

You can set properties in a background thread, but you have to delegate raising PropertyChanged event to the main thread.

As an example you could look here:

https://github.com/levitali/CompiledBindings/blob/master/source/XF/XFTest/ViewModels/SynchronizedObservableObject.cs

Though the project is for Xamarin Forms, there are compiler switches for many other UI frameworks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants