Skip to content
This repository has been archived by the owner on Dec 31, 2022. It is now read-only.

Exceptions being thrown from DeviceMonitor Dispose() #193

Open
vflame opened this issue Jul 9, 2020 · 1 comment
Open

Exceptions being thrown from DeviceMonitor Dispose() #193

vflame opened this issue Jul 9, 2020 · 1 comment

Comments

@vflame
Copy link

vflame commented Jul 9, 2020

When Dispose is called on DeviceMonitor after being Started, AdbExceptions are thrown from this.monitorTask.Wait();. Throwing exceptions from dispose is a bad practice.

Repro:

            var socket = new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort));
            using (DeviceMonitor monitor = new DeviceMonitor(Socket))
            {
                monitor.Start();
                Thread.Sleep(1000);
                monitor.Dispose(); //exception thrown
            }
@bddckr
Copy link

bddckr commented Jul 9, 2020

I'm seeing the same after the recent refactoring work (which I love btw!). In my case it's an AdbException that has an inner exception of a SocketException. For now I'm using this:

try
{
    monitor.Dispose();
}
catch (AggregateException exception) when (
    exception.Flatten().InnerExceptions is ReadOnlyCollection<Exception> innerExceptions
    && innerExceptions.Count == 1 && innerExceptions[0] is AdbException)
{
    // Ignored.
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants