/// <summary> /// Dispose handle. This will prevent action being called. /// </summary> public void Dispose() { WatchToken _token = Interlocked.CompareExchange(ref token, null, token); if (_token != null) { _token.UnregisterCallback(this); } action = null; state = null; token = null; }
/// <summary> /// Enumerate a directory at the given path, if any. /// </summary> /// <param name="filter">Relative path that identifies the directory.</param> /// <returns>Returns the contents of the directory.</returns> public IChangeToken Watch(string filter) { // Assert enabled feature if (!options.CanObserve) { throw new NotSupportedException(nameof(Watch)); } WatchToken watchToken = new WatchToken(); IFileSystemObserver observerHandle = FileSystem.Observe(filter, watchToken, null, null, token); Interlocked.CompareExchange(ref watchToken.observerHandle, observerHandle, null); return(watchToken); }
public CallbackHandle(WatchToken token, Action <object> action, object state) { this.token = token; this.action = action; this.state = state; }