This works great:
private void MainMethod()
{
Task<bool> taskItemFound = new Task<bool>(ItemFound);
}
private bool ItemFound()
{
//Do Work
return true;
}
This works but is UGLY and I can't pass more than one parameter:
private void MainMethod()
{
var startNew = Task<bool>.Factory.StartNew(TempMethod, "cow");
}
private bool TempMethod(object o)
{
return ("holy " + o == "holy cow");
}
I'm looking for a solution that will give me a Task<bool>
from an existing method with more than one input parameter and that returns a bool. Ideally, it would look like this:
Task<bool> taskItemFound = new Task<bool>(ItemFound(param1, param2, param3));
You can do:
bool result = await Task.Run(() => ItemFound(param1, param2, param3) );
Or if you really want it as Task<bool>
:
Task<bool> t = new Task<bool>(() => ItemFound(param1, param2, param3) );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With