473,320 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Add control to Panel from another thread, not UI thread

Hi misters,

I using BackgroundWorker control in my Windows Forms. In my form, I have a
SplitterPanel.

In DoWork event , I create controls child, and in ProgressChanged event I
try add controls to SplitterPanel, but the application not responds. I use
InvokeRequired for controls child.

Any suggestions, please ?

Thanks in advance.

Private Sub bgCargaFichero_DoWork(ByVal sender As System.Object, ByVal e As
System.ComponentModel.DoWorkEventArgs) Handles bgCargaFichero.DoWork

Try

'SplitContainer1.Panel1.SuspendLayout()

'SplitContainer1.Refresh()

' Procesar fichero

Me.ProcesarFicheroCargadoWork() ' IN THIS METHOD I CREATE CONTROLS Type =
ContenedorVisorBase

'SplitContainer1.Panel1.ResumeLayout(False)

If bgCargaFichero.CancellationPending = True Then

e.Cancel = True

Else

e.Result = True

End If

End Sub

Private Sub bgCargaFichero_ProgressChanged(ByVal sender As System.Object,
ByVal e As System.ComponentModel.ProgressChangedEventArgs) Handles
bgCargaFichero.ProgressChanged

Dim contenedorPagina As
GRUPOBACKUP.Administrador.Util.Cliente.ControlesWi ndows.ContenedorVisorBase =
Nothing

contenedorPagina = CType(e.UserState,
GRUPOBACKUP.Administrador.Util.Cliente.ControlesWi ndows.ContenedorVisorBase)

If contenedorPagina IsNot Nothing Then

AddMiniaturaToPanel(contenedorPagina)

End If

=====

Delegate Sub AddMiniaturaToPanelDelegate2(ByVal cCTL As Control)

Private Sub AddMiniaturaToPanel(ByVal cCTL As Control)

If cCTL.InvokeRequired Then

Dim d As New AddMiniaturaToPanelDelegate2(AddressOf AddMiniaturaToPanel)

Me.Invoke(d, New Object() {cCTL})

Else

SplitContainer1.Panel1.Controls.Add(cCTL) ' Here, the application not
responds !!!!

End If

End Sub


--
http://www.alhambra-eidos.es/web2005/index.html
www.kiquenet.net
http://www.setbb.com/putainformatica...opic.php?p=843
www.trabajobasura.com/solusoft

Aug 8 '08 #1
3 3691
This came up yesterday (I'll look for the post); "no" is the short
answer. Only the UI thread can talk to the UI; and only the UI thread
should be creating controls.

Marc
Aug 8 '08 #2
I'll look for the post

It was, in fact, you. Believe it or not, nothing has changed overnight
- the same answers still apply...

http://groups.google.com/group/micro...fef6fe7e82e09f

Marc
Aug 8 '08 #3

Hi,

First of all this is a C# NG, not VB.NET

and the answer is no, you cannot do it, you have to send the event to
the UI thread using Control.Invoke
Aug 8 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Duncan Mole | last post by:
Hi, I have created a control which draws a title bar and provides a drop down menu for a Smart Device Application. It seemed to work fine until I came to add an event handler to act on Paint...
17
by: No One | last post by:
Is there a way to keep a control centered inside a form without having to recalculate everytime the form is resized?
5
by: Dan | last post by:
Good Day All, I am having a problem in Visual Studio 2005 Beta 2. I am hoping someone might have an idea as to what is going on. I have an ActiveX User Control written using Visual Basic 6.0....
6
by: Tom Rowton | last post by:
This one has me a bit confused and I'm not finding what I need in the MSDN or by searching these forums, so here goes... I have a rather large, complex code-in-page WebForm (don't ask) and a...
19
by: Dales | last post by:
I have a custom control that builds what we refer to as "Formlets" around some content in a page. These are basically content "wrapper" sections that are tables that have a colored header and...
11
by: BoloBaby | last post by:
OK, check this out... I have a form with a panel control and button on it (outside the panel control). I have two event handlers - one handles the click event of the button on the form. The...
9
by: timnels | last post by:
I have an issue where I have a user control that is launched into a floating form. At some point later, I allow the user to "unfloat" the user control by reparenting it on a split container in...
15
by: rizwanahmed24 | last post by:
Hello i have made a custom control. i have placed a panel on it. I want this panel to behave just like the normal panel. The problem i was having is that the panel on my custom control doesnt...
4
by: =?Utf-8?B?UmljaEI=?= | last post by:
I am trying to create a project using the ASP.NET AJAX accordion control. I would like to dynamically add panes to the control with a form template added when the pane is added. I have tried...
7
by: RichB | last post by:
I am trying to get to grips with the asp.net ajaxcontrol toolkit, and am trying to add a tabbed control to the page. I have no problems within the aspx file, and can dynamically manipulate a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.