I have just started with parallel programming. I want to create an action delegate method that print a message on console. When I chenge Action<string>
to Action<object>
and PritMessage
parameter to to object its work but with 'string
compiler throws an error.
The best overloaded method match for 'System.Threading.Tasks.Task.Task(System.Action, object)'.
Argument 1: cannot convert from 'System.Action<string>' to 'System.Action<object>'
static void Main(string[] args)
{
string message = "test";
Action<string> print = PrintMessage;
Task task = new Task(print, message);
task.Start();
Console.ReadKey();
}
static void PrintMessage(string message)
{
Console.WriteLine(message);
}