I just need to create a function to checkbox that will return the current value of checkbox.
I wrote :
private void Checkbox_check()
{
if (checkBox1.InvokeRequired)
return (int)checkBox1.Invoke(new Func<int>(checked));
else
return checkBox1.Checked; // bad here i know
}
What is bad here, can someone just write correctly this function? I need Invoke because can't use in another Thread without invoke. I just search a forum and web about help but can't find solution anywhere.
Don't use
Func<>as it doesn't return anything. UseActioninstead.Getting the checked state from another thread, you could do like this:
I would not advise this, this could lead to deadlocks etc. I advise you to pass the checked value on the threadstart, so you don't have to do any crossthread calls.