In general the RTD topics are notified when they are disconnected, e.g. when the user deletes the formula in the cell.
The Excel-DNA IObservable implementation respects and implements this, but the story is not trivial.
The IObservable that is returned from a function like the GetObservableClock() has a Subscribe method, which must return an object that implements IDisposable. When the underlying RTD topic is disconnected, this IDispose.Dispose() will be called, giving you a chance to clean up.
Now when using the Observable.Timer(…) helper, you don’t get an easy way to see this behaviour unless you wrap it up a bit.
Maybe something like the code below (where I use a bit of a hack to simplify the code, because I know that Subscribe will only be called once, so the object itself can the ‘IDisposable’ I return from the Subscribe call).
I’ve not checked whether the code compiles or runs correctly, so probably leaving you with some debugging to do…
static IObservable<string> GetObservableClock()
return new MyTimer();
public class MyTimer : IObservable<string>, IDisposable
Observable.Timer(dueTime: TimeSpan.Zero, period: TimeSpan.FromSeconds(1)).Take(10) // small change to make this a finite stream
.Select(_ => DateTime.Now.ToString("HH:mm:ss"));
public IDisposable Subscribe(IObserver observer)
_innerDisposable = _innerObservable.Subscribe(observer);
public void Dispose()
// This will be called when the topic is disconnected
// Do any other cleanup here….
Debug.Write("Dispose called for MyTimer");
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/c6189558-b7a9-4bd3-8347-f77d41cf1d24n%40googlegroups.com.
You can use Cancellation tokens and chaining of tokens to register your cleanup events. This can be used as a circuit breaker to ensure all sources are cleaned up. I have used this technique before with RTD and sockets connections to ensure proper cleanup and disposal. Here is a link to some documentation that you may find helpful:
I don’t use reactive objects with RTD, however, how I have handled it has been to create a top level token source, create a token and pass it to the dependant or chained process (in my case a socket subscription manager), from there register a callback to invoke when the token is cancelled, which cleans up the references etc. Then to notify the stop action call Cancel on the top level source. This will send the notification down to the dependants and your cleanup will be called, the same way a cancellation token on async events is used.
Hope that helps
To view this discussion on the web visit