I have a winform app in the main form has a tabcontrol, one thread will create or remove tabpages very frequently.And some other background threads will get data and need to visit each tabpage's control inside it. the code is here and can work:
public void GetCustomerMessage()
{
if (this.tabControl.InvokeRequired == true)
{
CustomerInforHandler handler = GetCustomerMessage;
this.tabControl.Invoke(handler);
}
else
{
//code to update something in some tabpages
//with foreach tabpage in tabcontrols and use BeginInvoke
}
}
The problem is, I realize in fact the background thread need to visit the certain tabpage, not the tabcontrol, is it right check the InvokeRequired
property of the tabcontrol, or I need to check each tabpage's InvokeRequired
? because sometimes I feel the UI is block for a short time.
Is it mean when the tabcontrol can visit UI thread, does not equals all the tabpage inside it can do this? or something can be optimized?