I'm assuming it's possibly to do so as programs like google chrome have gone one better and put each tab on a separate process. So how can i put a GUI control such as a datagridview on a separate thread?
I don't think that you'll need a Thread for every single control else you'll have a huge number of threads and then you may start to run into all sorts of trouble.
Here's a couple of websites to get you started: http://www.albahari.com/threading/
http://msdn.microsoft.com/en-us/library/aa645740(VS.71).aspx
I believe that is not possible... In order to modify a control (eg. by adding a child to it), you need to be on the same thread that created the parent. Therefore, your child control would have to be created by the same thread that created its parent.
The only elements I can recall seeing created on different threads are non-modal dialogs and such, but that is only possible because the non-modal dialogs are new windows / forms.
Google Chrome might have each tab running in a different process, but that doesn't mean the actual UI elements representing the tabs weren't marshaled onto the main UI thread (the one that created the browser's containing window) for display.
Now of course you are still able to perform the work of loading the data for your grids on a separate thread, and Ardman's links will help you there. When you actually bind your data to the grids, though, you will need to do so on the UI thread (or more precisely, the thread that created the control you're modifying).
Hope this helps.
That is not the control that is in a seperate thread, but the request launched through the control.
Let's say you have two tabs opened on different addresses. You click on a link that directs you to another site on the first tab. Meanwhile, you click another link on the second tab.
First, you need to know that a thread might be launched when you click the link on the first tab, making it GUI responsive. This is the same with the second tab, when you clicked the link in it.
Second, we now have one thread (the main thread, also called the GUI-thread) which job is to handle the user interaction. Another thread processing the request from the link on the first tab, and another thread from the link on the second tab.
Third, while your link requests for both tabs are being processed, you might let's say open a new tab and doing a search on Google! Then, this requires your GUI to be responsive, even while the application, the browser, is occupied with your requests.
Fourth, on the background-threads' return, they will return to the main thread reporting the result of their work, that is, the Web response they obtained requesting to solve the DNS linked the the links clicked.
An interesting way to make it possible in C#, and keeping it as easy as possible, is through the BackgroundWorker
class.
Each instance of a BackgroundWorker
represents a thread. So, you need to instantiate as much of BackgroundWorker
as it is required by the application when a mouse-click is captured, when a user clicks a link. The request is then sent to the DoWork()
event which is raised when a call to RunWorkerAsync()
method is made.
Here's an interesting tutorial on how to use the BackgroundWorker