I'm investigating the possibility of rewriting a relatively small service from C++ to C#. The service has two main functions:
- Execute HTTP requests once in a while. They involve several high-level tasks like JSON encoding/decoding, base64 encoding/decoding, and HTTP requests themselves, for which C++ isn't awesome;
- Perform a number of real-time, audio-related tasks that have hard deadlines, for which C# isn't awesome.
The real-time tasks are handled by a separate library that does its own threading stuff and barely interacts with the rest of the service at all. The rest of the service feeds it a little bit of data, obtained from the HTTP requests, every 5 minutes or so.
The thing is, since the real-time part has hard deadlines, I can't really tolerate GC pauses on the library's threads. On my own code's side, there should be plenty of time for the GC to run between Web requests, but I can't tolerate that it kicks in while I'm trying to feed data to the library either.
I found that I can create a critical section in which the garbage collector won't start using GC.TryStartNoGCRegion()
, which solves half of the problem.
However, I still don't know if there is a way to tell the .NET GC to leave alone specific threads that don't run managed code. Is that possible?