I have been using the following line of code happily for a while now and it seems to do the job satisfactorily. I am looking to convert it to C#. I am trying to convert:
Dim result as string = Await Task(Of String).Factory.StartNew(Function() MyClass.PerformJob(param1,param2,param3))
I am entering the following code in C# :
string result = await Task<string>.Factory.StartNew((Func<string>) MyClass.PerformJob((param1,param2,param3));
This generates the following error:
'Cannot convert type 'string' to 'System.Func<string>'
I assume this is related to passing parameters in the way I am; I’m lost as to why this should work in VB.NET and not C#?
Many thanks for your help.
You are trying to cast the result of
MyClass.PerformJobmethod toFunc<string>when the result is of typestring. Use this: