Note that there are some explanatory texts on larger screens.

plurals
  1. POC# Thread-safe Extension Method
    primarykey
    data
    text
    <p>I may be waaaay off, or else really close. Either way, I'm currently SOL. :) </p> <p>I want to be able to use an extension method to set properties on a class, but that class may (or may not) be updated on a non-UI thread, and derives from a class the enforces updates to be on the UI thread (which implements INotifyPropertyChanged, etc).</p> <p>I have a class defined something like this:</p> <pre><code>public class ClassToUpdate : UIObservableItem { private readonly Dispatcher mDispatcher = Dispatcher.CurrentDispatcher; private Boolean mPropertyToUpdate = false; public ClassToUpdate() : base() { } public Dispatcher Dispatcher { get { return mDispatcher; } } public Boolean PropertyToUpdate { get { return mPropertyToUpdate; } set { SetValue("PropertyToUpdate", ref mPropertyToUpdate, value; } } } </code></pre> <p>I have an extension method class defined something like this:</p> <pre><code>static class ExtensionMethods { public static IEnumerable&lt;T&gt; SetMyProperty&lt;T&gt;(this IEnumerable&lt;T&gt; sourceList, Boolean newValue) { ClassToUpdate firstClass = sourceList.FirstOrDefault() as ClassToUpdate; if (firstClass.Dispatcher.Thread.ManagedThreadId != System.Threading.Thread.CurrentThread.ManagedThreadId) { // WHAT GOES HERE? } else { foreach (var classToUpdate in sourceList) { (classToUpdate as ClassToUpdate ).PropertyToUpdate = newValue; yield return classToUpdate; } } } } </code></pre> <p>Obviously, I'm looking for the "WHAT GOES HERE" in the extension method.</p> <p>Thanks, wTs</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload