I'm new to multi-threaded C#, so this is probably a pretty simple/basic question. I have a console app that uses a single worker thread to execute a task. When the worker task finishes, i want to exit the console app with an int. I'm confused about how to do this, since the Main() method requires a return value, but the thread executes asynchronously. Here's what I'm trying to do:
class Program
{
static void Main(string[] args)
{
var exitCode = 1;
var deploymentManager = new DeploymentManager(() =>
{
exitCode = 0;
return exitCode; //<----- doesn't work because main() needs to return something immediately
});
var workerThread = new Thread(deploymentManager.Deploy);
workerThread.Start();
}
}
This illustrates, how I want to return the exitcode value, only when the thread has finished and executes the callback action.