Put the GUI control in a different thread?

I assume this is possible, since programs like google chrome went better and put each tab in a separate process. So, how can I put a GUI control like datagridview in a separate thread?

+3
source share
4 answers

I believe that this is impossible ... To change a control (for example, adding a child to it), you must be in the same thread that created the parent. Therefore, your child control must be created by the same thread that created the parent.

The only elements that I can remember seeing seeing created on different threads are modeless dialogs, etc., but this is possible only because modeless dialogs are new windows / forms.

Google Chrome may have each tab in a different process, but this does not mean that the actual user interface elements representing the tabs were not placed in the main user interface thread (the one that created the browser containing the window) for display.

Now, of course, you can still do the work of loading the data for your grids into a separate stream, and the Ardman links will help you there. However, when you actually bind your data to grids, you will need to do this in the user interface thread (or, more precisely, in the thread that created the control you are modifying).

Hope this helps!

0

, , .

, , . , . .

-, , , . , .

-, ( , GUI-), . .

-, , Google! , , , , .

-, , , Web, , DNS, .

# , BackgroundWorker.

BackgroundWorker . , BackgroundWorker, , . DoWork(), RunWorkerAsync().

, BackgroundWorker

0
0

I do not think that you will need a thread for each individual control, otherwise you will have a huge number of threads, and then you may encounter all the troubles.

Here are some websites to help you get started: http://www.albahari.com/threading/

http://msdn.microsoft.com/en-us/library/aa645740(VS.71).aspx

-1
source

Source: https://habr.com/ru/post/1734829/


All Articles