OpenMacroBoard / StreamDeckSharp

A simple .NET wrapper for Stream Deck
MIT License
351 stars 47 forks source link

Exceptions when disposing of a deck in WPF #45

Closed jskeet closed 2 years ago

jskeet commented 2 years ago

Not sure if this is WPF-specific, but I wouldn't have thought so...

To reproduce:

private void OpenAndDispose(object sender, RoutedEventArgs e)
{
    var devices = StreamDeck.EnumerateDevices().ToList();
    var device = devices[0];
    var deck = StreamDeck.OpenDevice(device.DevicePath);
    deck.Dispose();
}

Each time the button is clicked, there are three exceptions:

Is there a safe way of disposing of the deck objects?

wischi-chr commented 2 years ago

Currently all of those exceptions are handled and shouldn't really surface. Besides the fact that using exceptions for control flow is probably not a good design decision those exceptions shouldn't prevent anything from being disposed safely or am I missing something?

jskeet commented 2 years ago

Only that they're a bit worrying in terms of potentially being a sign of something else being wrong (and showing up in VS output, which makes me wonder whether they're not actually being handled).

wischi-chr commented 2 years ago

I just released a preview version v4.0.0-preview. This is a breaking change, but it should be pretty straight forward to migrate. This version also fixes the "exceptions for control flow" situation in the device Dispose method.

Pls let me know if it works for you.

jskeet commented 2 years ago

Fabulous - thanks so much. I'll test all of these over the weekend.

jskeet commented 2 years ago

Yup, they all look good for me, thanks - see https://github.com/jskeet/DemoCode/commit/87c8c65d14dbc1710cffc4ba3febe228ff86475d for the migration, if anyone else needs to do the same thing.

ocdtrekkie commented 2 years ago

@jskeet That's a super useful link that @wischi-chr may wish to link to or reference elsewhere. I saw some comments about having to "migrate" to 4.0.0, but not a super clear example of how to do so.

jskeet commented 2 years ago

@ocdtrekkie: Glad it's useful! It's worth noting that this is a fairly simple project - there may well be other migration changes required that I haven't covered, but if it's a useful starting point, that's great :)

wischi-chr commented 2 years ago

@jskeet thank you for sharing the changes you had to make. @ocdtrekkie sadly I'm currently a bit short on time so there is no "good" migration guide at the moment. You could also take a look at the changes of the example projects here.

I added both links (jons DemoCode project and the diff view of the ExampleCollection repository to the README.md of this repository).