a quick and dirty example..Â
GetAsyncValue should refresh if any event updates global state (call SetGlobalStateValue).
using ExcelDna.Integration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Reactive.Threading.Tasks;
using System.Text;
using System.Threading.Tasks;
namespace excelDnaReactiveExample
{
  public static class Functions
  {
    [ExcelFunction(Description = "Set the global state value")]
    public static object SetGlobalStateValue(int i)
    {
      GlobalState.ValueSubject.OnNext(i);
      return i;
    }
    [ExcelFunction(Description = "Returns the global state value")]
    public static object GetGlobalStateValue()
    {
      return GlobalState.ValueSubject.Value;
    }
    [ExcelFunction(Description = "Async UDF that updates when global state changes")]
    public static object GetAsyncValue()
    {
      string functionName = "GetAsyncValue";
      object paramInfo = null; // could be one parameter passed in directly, or an object array of all the parameters: new object[] {param1, param2}
      return ObservableRtdUtil.Observe(functionName, paramInfo, () => GlobalState.ValueSubject.AsObservable());
    }
    public static class GlobalState
    {
      private static int _value;
      public static BehaviorSubject<int> ValueSubject { get; } = new BehaviorSubject<int>(_value);
      public static int Value
      {
        get => _value;
        set
        {
          _value = value;
          ValueSubject.OnNext(value); // Notify subscribers when the value changes
        }
      }
    }
    public static class ObservableRtdUtil
    {
      public static object Observe<T>(string callerFunctionName, object callerParameters,
        Func<IObservable<T>> observableSource)
      {
        return ExcelAsyncUtil.Observe(callerFunctionName, callerParameters,
          () => new ExcelObservable<T>(observableSource()));
      }
      // An IExcelObservable that wraps an IObservable
      class ExcelObservable<T> : IExcelObservable
      {
        readonly IObservable<T> _observable;
        public ExcelObservable(IObservable<T> observable)
        {
          _observable = observable;
        }
        public IDisposable Subscribe(IExcelObserver excelObserver)
        {
          var observer = new AnonymousObserver<T>(value => excelObserver.OnNext(value), excelObserver.OnError,
            excelObserver.OnCompleted);
          return _observable.Subscribe(observer);
        }
      }
    }
  }
}
thanksÂ
Kedar
(Looking for my next assignment - kedarkulkarni78 at gmail)