471,344 Members | 1,006 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,344 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

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




' Procesar fichero

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


If bgCargaFichero.CancellationPending = True Then

e.Cancel = True


e.Result = True

End If

End Sub

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

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

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

If contenedorPagina IsNot Nothing Then


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})


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

End If

End Sub


Aug 8 '08 #1
3 3572
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.

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...


Aug 8 '08 #3


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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Duncan Mole | last post: by
17 posts views Thread by No One | last post: by
5 posts views Thread by Dan | last post: by
4 posts views Thread by =?Utf-8?B?UmljaEI=?= | last post: by
reply views Thread by Ronak mishra | last post: by

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.