So, I would like to use the new Task class (years ago I would use BackgroundWorker) to do the following but I'm unsure how to get it working. Apologies, I'm rusty...
internal bool DoThisThing(string input) {...} // Takes a while.
private void toggleButton_Click(object sender, RoutedEventArgs e)
{
string toggleButtonName = "hi!";
Func<string, bool> delToUse = new Func<string, bool>(DoThisThing); // Delgate of appropriate type
Task<bool> task = new Task<bool>(delToUse); // Doesn't like this. Something I can do instead?
... // do other things for a while
// Task takes a while, don't want to block UI thread, use Task.
task.Start(toggleButtonName); // Looks like Start method doesn't allow input parameters for the assigned delegate like this. How can I accomplish something similar?
... keep on going and let Task finish. Maybe check the result, maybe not.
}
Hopefully that makes some sense?
From what I've seen from searching, it looks like Lambda expressions are used most frequently. I never really used them much so I was (at first) trying to find a more verbose way of accomplishing the same thing.
Thanks!