Question

I am writing a Spotify app in C#.

I am currently verifying that the sp_session_process_events() call is working properly. Trying to be very scientific about it, I've been using the out parameter nextTimeout to try and prevent the need for the lib to call NotifyMainThreadCallback.

The call seem to be as frequent with that feature as without it. The value of nextTimeout does not seem to be that valid everytime either. Below is a short example when I am only calling sp_session_process_events when required bý NotifyMainThreadCallback.

00:00:08.299: - NotifyMainThreadCallback
00:00:08.312: sp_session_process_events() next process requested in 1000 ms
00:00:08.376: - NotifyMainThreadCallback
00:00:08.381: - NotifyMainThreadCallback
00:00:08.389: sp_session_process_events() next process requested in 922 ms
00:00:08.396: - UserinfoUpdatedCallback
00:00:08.401: - NotifyMainThreadCallback
00:00:08.409: sp_session_process_events() next process requested in 15 ms
00:00:08.415: - MetadataUpdatedCallback
00:00:08.419: sp_session_process_events() next process requested in 891 ms

So why use the nextTimeout at all? As far as I can see it can be ignored.

Was it helpful?

Solution

The next_timeout value is there to prevent you from calling sp_session_process_events too frequently, and is not necessarily intended to reduce the number of main thread 'wake-ups'. I don't see anything unusual about the timeout values you're seeing.

The notify_main_thread callback is often invoked from sp_session_process_events, which you should be calling from the main thread anyway. This shouldn't cause you huge problems. I suppose you could add some extra logic to stay in the event loop rather than signalling in those cases, but that could require more synchronisation than you already have.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top