CommunityToolkit / CommunityToolkit/dotnet

Proposal: Allow Mvvm's ObservableObject's PropertyChanged event to fire on the thread that added the event handler

Aperta
#28 0 commenti 1 reazione 0 assegnatari Vedi su GitHub
feature request :mailbox_with_mail: open discussion :telephone:
Lingua principale
C#
Stelle
3.8k
Fork
400
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## Summary

In some cases, mainly UI frameworks, it is required to fire events on the thread that added the event handler. For example, a multi window application may use and reuse the same view model on different User Interface Threads. Updating the UI would require the event to be fired on the correct thread in order to work.

A good example of an UI framework needing this, is Windows.UI.Xaml (details about a proposal to change its behavior here: https://github.com/microsoft/microsoft-ui-xaml/issues/2795)

## Details

This functionality cannot be added by an app developer without having to fork the library. Further more, forcing such functionality on every developer could break existing code behaviors, as well as add a performance impact on existing code which isn't needed.

A solution to this problem would be to make the behavior opt in, either by the use of a flag in the class, or by having another distinct class like ```SynchronizedObservableObject``` providing this functionality.

The former might require less code changes than the later, but would prevent an app developer from mixing both behaviors at will.

[Updated]

Aside from Windows.UI.Xaml the issue could be happening in other UI frameworks as well. Relying on the UI frameworks to change this behavior will always be the preferred option but unfortunately like in the case of Windows.UI.Xaml, changes may never come to previous versions of the framework that are supported on other platforms.

## Further more

Some discussion has happened on this subject on the UWP Community Discord, about this problem and a potential way to solve it, more details here: https://canary.discord.com/channels/372137812037730304/669640275500466197/908427474747158588

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Non vengono indicati file del repository né test; inizia individuando ObservableObject di Mvvm e l'invocazione del suo evento PropertyChanged. Confronta un flag opt-in con un SynchronizedObservableObject distinto, quindi definisci test che dimostrino che i gestori vengono eseguiti sul thread che ha effettuato la sottoscrizione, preservando il comportamento esistente per impostazione predefinita.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
csharp
Ambito
desktop, frontend
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.