DubyaDude / WindowsMediaController

Allows developers to more easily get information from and interact with the Windows 10/11 OS media interface. (Also referred to Windows System Media Transport Controls (SMTC))
https://nuget.org/packages/Dubya.WindowsMediaController
MIT License
129 stars 9 forks source link

Unhandled exception #7

Closed VolcanicArts closed 1 year ago

VolcanicArts commented 2 years ago

Running Spotify, then closing it after around 5/10+ seconds and after using the controls, this error gets thrown.

Unhandled exception. System.Runtime.InteropServices.COMException (0x800706BA): The RPC server is unavailable. (0x800706BA)
   at WindowsMediaController.MediaManager.MediaSession.OnSongChange(GlobalSystemMediaTransportControlsSession controlSession, MediaPropertiesChangedEventArgs args)
   at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_1(Object state)
   at System.Threading.QueueUserWorkItemCallbackDefaultContext.Execute()
   at System.Threading.ThreadPoolWorkQueue.Dispatch()
   at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
   at System.Threading.Thread.StartCallback()
DubyaDude commented 2 years ago

This might be related to https://github.com/DubyaDude/WindowsMediaController/issues/6 Do you have the issue with the CMD example that was spoken about in there?

Also, would be good to see what the CMD example says exactly w/ annotations of what action you/user takes ( like done here: https://github.com/DubyaDude/WindowsMediaController/issues/6#issuecomment-1279820627 )

VolcanicArts commented 2 years ago

The CMD sample doesn't throw the error but it does produce something interesting. Somehow in the middle of pausing (in this case closing Spotify) it tries to play?

image

Context for this is I pressed play, pause, skip, previous, shuffle, just a few times and after around 10 seconds then closed Spotify. All the lines in the screenshot were produced after I closed Spotify.

Also for thoroughness I tested this right after Spotify was opened and then closed it and it also has the same spam pause and execute play once behaviour.

This exception has been reproducible using the steps mentioned 1st (but not mentioned 2nd?) even after trying steps mentioned in #6 like a PC restart, log in/out, etc...

Best case bet is maybe to just listen for unavailable RPC server exceptions and ignore the error since it's technically not an issue if it's unavailable, since if it's unavailable the program producing the media has likely been closed, which can be confirmed by OnAnySessionClosed.

DubyaDude commented 1 year ago

I see, so it's reproducible in the UI sample? If possible can you give a 'step-by-step detailed guide for dummies'? Not having any luck reproducing on my end.

Also yes, you can see similar behavior from my previous example https://github.com/DubyaDude/WindowsMediaController/issues/6#issuecomment-1279820627 on what Spotify does when closing. This is just part of Spotify's (and a few others') shutdown process. I wish I knew exactly why, but that would need to be answered by the media player's dev team.

VolcanicArts commented 1 year ago

I'm having trouble reproducing it in the UI sample, and has honestly got me stumped because I'm also having trouble reproduce it when using my app now.

I'd say for now this issue isn't solved but partly resolved... I'll do some more fiddling to see if I can reproduce it but if it never comes up again I guess it's just down to a blip. It could even be possible that it was to do with my machine since I had to rollback a Windows update earlier today (and I've had no reports from users that closing Spotify crashes my app)

Either way thanks for your help.

DubyaDude commented 1 year ago

I see, well if you run into it again you're more than welcome to re-open.

DubyaDude commented 1 year ago

Reopening, ran across the bug while testing for another issue on the same exact line. Seems like an odd timing issue, will add a handle to this exception.

Aytackydln commented 1 year ago

When I started using OnFocusedSessionChanged I also started to get this exception. I solved my case by using Dispose pattern where I subscribed to the event and fixed after pc restart

nvm, I started getting it after debugging

DubyaDude commented 1 year ago

Did two changes to handle this in release 2.3.2:

If you still encounter it, please reopen.