The problem is that you started the task when you call TaskFactory.StartNew
– I mean, it’s even in the name of the method that you are starting the task. StartNew
creates the task, then calls Start
on your behalf. =D
If you want, you can either Wait
on the task, like @Peter Ritchie said, or you can create the task manually like so:
var task = new Task(() => { ... });
task.RunSynchronously();