This code runs on Visual Studio 2019 but fails to compile on Visual Studio 2012
Task.Factory.StartNew(HandleMessages);
public async Task HandleMessages()
{
...
}
Visual Studio 2012 shows this error
The call is ambiguous between the following methods or properties: 'System.Threading.Tasks.TaskFactory.StartNew(System.Action)' and 'System.Threading.Tasks.TaskFactory.StartNew<System.Threading.Tasks.Task>(System.Func<System.Threading.Tasks.Task>)'
I can fix this error like this :
Task.Factory.StartNew<Task>(HandleMessages);
But I can't understand why does Visual Studio 2019 compile it without showing any error while Visual Studio 2012 rejects it.
I'm building an application using the following:
- Visual Studio Community 2019
- WinForms
- C# 5.0
- .Net Framework 4.5
I have the same setup for the Visual Studio 2012
Tried building the solution using MSBuild it shows the same error that Visual Studio 2012 does.
I need to know why does Visual Studio 2019 accepts this code and if there is a way to make it behave the same way Visual Studio 2012 does.