BarRaider / obs-websocket-dotnet

C# .NET library to communicate with an obs-websocket server
MIT License
224 stars 104 forks source link

[BUG] #131

Open tgudelj opened 1 year ago

tgudelj commented 1 year ago

Issue Type

Multi-threading issue with sequence of events

Describe the bug I don't know if it is a bug or feature, but in some cases it will manifest as a bug: obs-websocket-dotnet handles messages received from obs in parallel, spawns a new thread for each message received:

wsConnection.MessageReceived.Subscribe(m => Task.Run(() => WebsocketMessageHandler(this, m)))

In WebsocketMessageHandler if message is an event it again spawns a thread to process the event

Task.Run(() => { ProcessEventType(eventType, body); });

The net result is that events are not processed in sequence of arrival and obs-websocket-dotnet events are not raised in actual sequence they arrived from OBS. So why does it matter?

Well, in my case I was trying to synchronize a slider UI control to input volume, updating the slider position on InputVolumeChanged. Let's say user changed volume from 10 to 0, I'd expect sequence like 10,9,7,6,5,3,2,0 and instead get 10, 7, 5, 6, 2, 1, 0, 3.

Again, I'm not sure if this should be classified as bug or not, but in my particular case sequence of events does matter

To Reproduce see description

Expected behavior Events raised in order they are sent by OBS websocket

Versions OBS Version: OBS WebSocket Version: 5.x OBS WebSocket Dotnet (this library) Version: 5.x OS: [e.g. Windows 10]