I know that there are a lot of questions (and respectfully answers) related to this topic on this site, but as I am a newbie to C#, I still cannot figure out which solution works for me and that is why I decided to describe my situation here.
I write an application, which starts with the main method:
class Program
{
static void Main(string[] args)
{
}
}
In this main method, I have to implement checking for new folders every 10 minutes.
I have another class defined for that - NewFoldersChecker, and static method in it "CheckForNewFolders"....so I hoped that a method in the class Program like this:
private static void CheckForNewFolders()
{
Task.Run(async () =>
{
while (true)
{
NewFoldersChecker.CheckForNewFolders();
await Task.Delay(60000);
}
});
}
and calling it from the main method would do the job:
static void Main(string[] args)
{
CheckForNewFolders();
}
But obviously, this is not the case - the method is called once and that is all because the main thread ends.
What should I do to keep the main thread alive or what are my other options?