I am debugging a WinForm control and it returns InvokeRequired = true although i am on Main thread. Is it possible for a control to be child of a non-UI thread? I thought control which is an UI component can only be child of UI thread.
Asked
Active
Viewed 410 times
1 Answers
0
Yes, it is possible, that control was created on some other thread than application (ui) thread, please see example bellow.
var task = Task<Button>.Factory.StartNew(() => {
var button = new Button();
var thisForcesControlToCreateHandle = button.Handle;
return button;
});
var taskResult = task.Result;
var invokeRequired = taskResult.InvokeRequired; // will be True
It is important to read control property Handle, that forces handle creation, see http://msdn.microsoft.com/en-us/library/system.windows.forms.control.invokerequired.aspx form more info.

SetyCZ
- 150
- 7