Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You could use a variation on the Observer pattern to the same effect. Not sure what your threading requirements are, and I suspect this suffers from similar dereferencing problems as <a href="https://stackoverflow.com/questions/289002/how-to-raise-custom-event-from-a-static-class/289358#289358">How to raise custom event from a Static Class</a> (although would have to play with the code a bit more to bottom that out):</p> <p>using System; using System.Collections.Generic;</p> <p>namespace ClassLibrary1 { public class StaticObservable { private static int currentNumber;</p> <pre><code> private static readonly List&lt;IObserver&gt; observers = new List&lt;IObserver&gt;(); public static int CurrentNumber { get{return currentNumber;} set { currentNumber = value; foreach (var observer in observers) { observer.NotifyChange(); } } } public static void Attach(IObserver observer) { observers.Add(observer); } public static void Detach(IObserver observer) { observers.Remove(observer); } } public interface IObserver { void NotifyChange(); } public class ObserverImpl : IObserver { public void NotifyChange() { Console.Out.WriteLine("Number has changed"); } } public class AppWrapper { public static void Main (string[] args) { Console.ReadLine(); var observerImpl1 = new ObserverImpl(); var observerImpl2 = new ObserverImpl(); StaticObservable.Attach(observerImpl1); StaticObservable.Attach(observerImpl2); StaticObservable.CurrentNumber = 1; Console.ReadLine(); } } </code></pre> <p>}</p>
    singulars
    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.
    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