keijiro / OscJack

Lightweight C# implementation of OSC server/client
The Unlicense
476 stars 65 forks source link

Monitor causes thread to crash when having multiple threads #42

Open Tehenauin opened 1 year ago

Tehenauin commented 1 year ago

I have 2 OSC servers, that receive messages with the same adress from different ports. Every time I started the application, one of the threads was stopping to work after a while. I found out, that it has something to do with the string builder, that throws an exception when 2 threads are trying to access it at the same time.

my simple but ugly solution for this is adding a _logging bool to the monitor class and wrapping the content of the MonitorCallback method in

if (_logging) return;
 _logging = true;

...

_logging = false;

This way the monitor does not start a new log when already logging. It does also mean that some messages do not get logged tho. But I am fine with that. Of Course some kind of queue would probably be nicer here.

Tehenauin commented 1 year ago

It seems, that my solution doesnt work completely, it can still happen, just not as often as before.