I'm programming a C# software and it has some functions which make like a check-in on my server 5 in 5 seconds (they send http request, but it doesn't matter for my problem). Here is the code:
log();
while (true)
{
alive(); // this sends an http request to my server
Thread.Sleep(5000); // sleep for 5 seconds avoiding computer overcharge
}
MessageBox.Show("after infinite loop"); // this is never executed but i pretend to do so
So, my problem is: I got an infinite loop and after that infinite loop I want to write ANOTHER infinite loop which runs asynchronously and does something each 100ms. Of course "that something" i cannot write it inside the existing loop because that loop is executed 5 in 5 seconds. I got to code a lot of infinite loops like those, each one being executed independently from another (or asynchronously) with different times.
I have searched a lot and my conclusion is to write every loop asynchronously. My question is: how to do that? Every code I found was completely incomprehensible for me. I simply couldn't understand them. So, if you have a better option than async infinite loops (which i think is the best option indeed), you can speak about it, otherwise i need some help coding this async infinite loops...
Sorry for my bad english, thanks in advance