Closed NeverMorewd closed 5 months ago
public Observable<AutomationElement> ObserveElementsFromCurrentPoint(CancellationToken cancellationToken) { return Observable.CreateFrom(t => { return ElementsFromCurrentPoint(cancellationToken); }); } private async IAsyncEnumerable<AutomationElement> ElementsFromCurrentPoint([EnumeratorCancellation] CancellationToken cancellationToken) { while (true) { if (cancellationToken.IsCancellationRequested) { break; } await Task.Yield(); yield return ElementFromCurrentPoint(); } } public AutomationElement ElementFromCurrentPoint() { try { var element = _automationBase.FromPoint(Mouse.Position); return element; } catch (UnauthorizedAccessException) { // when this error is threw,the observable is interrupted! throw; } }
My mistake.The UnauthorizedAccessException breaks the looping.