Am trying to read the value of a checkbox from a BackgroundWorker in WPF:
This doesn't work:
bool? isSleepChecked = checkBoxSleep.Dispatcher.Invoke(DispatcherPriority.Normal, (ThreadStart)delegate{ return checkBoxSleep.IsChecked;});
Cannot convert anonymous method to delegate type 'System.Threading.ThreadStart' because some of the return types in the block are not implicitly convertible to the delegate return type
EDIT - Here is HB's answer expressed using a delegate instead of lambda which I find slightly more readable
bool? isSleepChecked = (bool?)checkBoxSleep.Dispatcher.Invoke(new Func<bool?>(delegate { return checkBoxSleep.IsChecked; }));