mirror of
https://github.com/qmlnet/qmlnet.git
synced 2026-05-16 14:15:57 -06:00
[GH-ISSUE #112] Ensure that all UI-related methods are called in the UI thread. #68
Labels
No labels
bug
enhancement
help wanted
help wanted
pull-request
question
todo
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/qmlnet#68
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @pauldotknopf on GitHub (Mar 23, 2019).
Original GitHub issue: https://github.com/qmlnet/qmlnet/issues/112
This includes things like activating signals, working with
INetJsValue, etc.This will ensure correctness in programs.
There will be an option to delete it for unit testing. By default, it will be enabled.
@pauldotknopf commented on GitHub (Mar 23, 2019):
You will likely want to disable this for unit tests.
@WingedToaster commented on GitHub (Sep 13, 2019):
How do I force a task to run on the UI thread? I have a serial port device and it is receiving data in a secondary thread. I am validating the data an then need to show a result screen but I am running up against this exception.
@TripleWhy commented on GitHub (Jan 11, 2020):
@pauldotknopf Any progress on this? Or perhaps a recommendation on how to raise signals from non-UI threads?
This is possible in Qt, actually it is one of its core features.
In Qt, we can even choose how inter-thread signals are handled, per connection: <https://doc.qt.io/qt-5/qt.html#ConnectionType-enum
As a side note, this can't be done from the C#-side, since the main thread is locked in the
app.Exec()call.@WingedToaster commented on GitHub (Jan 11, 2020):
https://github.com/qmlnet/qmlnet/issues/165
@TripleWhy commented on GitHub (Jan 11, 2020):
Thanks for this.
But since you don't sound convinced you did it correctly, and because this is the place where the exceptions sends you to, I would still like to see an official recommendation here.
@WingedToaster commented on GitHub (Jan 11, 2020):
No worries. My last post on the issue is pretty much how it stayed and now it’s on 11 devices out in the wild, soon to be 200.
@pauldotknopf commented on GitHub (Jan 11, 2020):
This issue was about ensuring, via validation, that all interactions with QObjects-and-friends where on the main thread. I have done this. See this.
As for running actions on the UI thread, this is done, and there are a few options.
Qml.Net.Signals.ActivateSignaldo things correctly, just like in Qt land. The handlers for the signals get called on the thread that owns the QObject (the main thread).Qml.Net.QCoreApplication.Dispatch(Action action)andawait Qml.Net.QCoreApplication.DispatchAsync(Func<Task> action). These allow you to dispatch .NET delegates to the UI thread. In my applications, I create anIDispatcherinterface.This allows me to keep Qt-specific bits out of my business logic, while still having the concept of a "GUI" thread.
In the .NET types that I register with QML, I listen to some global system-level events. I use this interface to jump back into the GUI thread so that I can update properties/etc.
@TripleWhy commented on GitHub (Jan 11, 2020):
Thanks for the reply. I am using exactly what you have described in 1, and have never expected there to be an issue. Yet, after I upgraded the Qml.Net version to 0.10.1 recently, I suddenly get the exception that sends me here, anytime I want to activate a signal from a non-UI thread.
That is caused by this line. Stack trace, in case you are interested:
@pauldotknopf commented on GitHub (Jan 11, 2020):
Oh, I see.
Yeah, that might be a little too aggressive. We should probably remove that check in
NetReference.ActivateSignal.