Hi,
I've created a UserControl. This usercontrol contains multiple sub-controls each will be loaded with values at the time of intial load based on various conditions.
Multiple instances of this usercontrol will be called in the Main form. Since each instance has to load its sub-controls with initial default values, the Main Form takes a long time to Load.
Can someone please help me in calling each instance of this usercontrol via individual threads so that the Main Form Loads quicker?
Thanks.
Loading
EhteshamPosted Apr 19, 2013, 1:44 PM
{
delegate void LoadDelegate();
LoadDelegate delegateInstance;
public Form1()
{
InitializeComponent();
delegateInstance = new LoadDelegate(this.LoadControls);
IAsyncResult handle = delegateInstance.BeginInvoke(null, null);
handle.AsyncWaitHandle.WaitOne(50000);
}
void LoadControls()
{
//load your controls here
}
}
Sam HobbsPosted Oct 18, 2011, 1:45 PM
The Windows operating system does not support use of a window from any other thread than the thread that owns the window. It sometimes can be done but .Net will issue an exception when we we try so that we understand that it is likely to be a problem.
I assume that the user controls do more than just create controls; they get data, correct? You can create threads to do that other processing; you might want to create a queue of work done and a thread pool, since it might not help if you create a separate thread for each user control. Depending on what needs to be done, it might work to use asynchronous reads to get the data, but you say nothing about what the user controls do.
If you can be more specific about what needs to be done, then you are more likely to get more specific suggestions.