I want to have a thread that have a permanent lifetime (think of it like a process) and that manages a resource (a critical section in my case it's a 3G modem accessed via a serial port).
Other threads will send requests to this thread via a method and wait until it sends a response or a timeout has expired.
I can achieve this with the Qt C++ framework but I didn't find an easy way to do it in C# (I already asked a question the other time and someone told me about the threading context but he didn't answer my question), I have to write something like Qt's signal/slot system and it's a tedious task.
A colleague told me to take a look at AsyncEx but I haven't found an example that illustrates what I want to achieve and I'm not sure if it will help (neither will the async/await stuff).
It really pisses me off because I have a C# buggy code that uses locks (concurrency bugs and no it's not me who wrote it) and I would like to use this threading model to refactor it.
It's unbelievable that only Qt has done something powerful to handle this case (thread aware signals/slots and event loops), the others only offer useless garbage.
Update : In Qt, we can't invoke a method with timeout. It will block until the other thread sends a reply and according to this https://bugreports.qt.io/browse/QTBUG-63870 it's better to perform a non-blocking request...
Update 2 : Following JonasH's answer, I made this example : https://github.com/embeddedmz/message_passing_on_csharp which could be useful for people who share the same point of view as me concerning the threading model (message passing) which in my opinion is much less harmful than others (you know the multi-threaded programs which work well most of the time, for me it's binary it's either works all the time or nothing).
I will share another solution found by my work colleagues when they will show it to me in a future update.