• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Each Control in a separate thread

Hello,

I am creating a form that contain alot of usercontrols, these user controls is heavy and contain a lot things do,
I want to know a way how to :
When loading the form each control run in a separate thread.

I use some code like that to load the controls:
Dim ctrl1 as new MyUserControlType
Dim ctrl2 as new MyUserControlType
Dim ctrl3 as new MyUserControlType

form.Controls.Add(ctrl1)
form.Controls.Add(ctrl2)
form.Controls.Add(ctrl3)

Please help,

Thanks,
0
amrelgarhy81
Asked:
amrelgarhy81
  • 2
2 Solutions
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Controls run in the same thread as the form that contains them...

Did you create the UserControls?  You can make the code INSIDE the UserControls run in a seperate thread.
0
 
gregoryyoungCommented:
"Did you create the UserControls?  You can make the code INSIDE the UserControls run in a seperate thread."

Even if you create threads inside of the various controls to handle their tasks it really depends what they are doing as to whether or not there will be a gain. Even if you have multiple threads running in these controls those threads still have to broker any changes to the controls back to the main thread (only the thread that creates a control can access it) as such if your controls are spending their time updating their visual representation even adding additional threads within the controls will not help.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
This is true.  =)

It all depends on what we're doing here...

Can you gives us more details about the UserControl amrelgarhy81?

Along with a bigger picture of the application?
0
 
amrelgarhy81Author Commented:
Hello,

The application is a small designer application for windows application, and use some user controls i made for it like:
Scroll Image Control (Load in it number of images to move one after one in run time)
Custom PictureBox control (Load in it number of images to move one after one in run time)
Windows media control (playing medias)
When loading the .exe file that the design create the controls run slow on the form and very slow when loading and closing.
I thought that running each control in a separate thread  may solve this porformance shortening.
Notes:
In these controls like the Scroll Image Control i use a timer to slide the images while running.


thanks,
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now