P
Phil Jones
I'm trying to add a control to a form when a user clicks a button - the
contol takes a long time to load.
To make the app appear responsive, I want to do this in the background
(displaying a simple "Loading" message). How do I go about this? I've
tried creating a new thread, and useing the Control.BeginInvoke method - but
the result is that the control created within the different thread does not
appear (see example below).
Is this because the contol is created on a different thread. Please, what
is the correct way to program this type of behaviour.
Many thanks!
===
Phil Cockfield
(Auckland | Aotearoa)
==============================================
Imports System.Threading
Public Class UserControl1
Inherits UserControl
Delegate Sub dAddControl()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim d As New dAddControl(AddressOf Me.AddControl)
Dim ar As IAsyncResult = d.BeginInvoke(Nothing, Nothing)
Me.BackColor = Color.Salmon
End Sub
Sub AddControl()
Dim c As New UserControl2
Me.Controls.Add(c)
c.Width = 350 : c.Height = 50
End Sub
End Class
contol takes a long time to load.
To make the app appear responsive, I want to do this in the background
(displaying a simple "Loading" message). How do I go about this? I've
tried creating a new thread, and useing the Control.BeginInvoke method - but
the result is that the control created within the different thread does not
appear (see example below).
Is this because the contol is created on a different thread. Please, what
is the correct way to program this type of behaviour.
Many thanks!
===
Phil Cockfield
(Auckland | Aotearoa)
==============================================
Imports System.Threading
Public Class UserControl1
Inherits UserControl
Delegate Sub dAddControl()
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim d As New dAddControl(AddressOf Me.AddControl)
Dim ar As IAsyncResult = d.BeginInvoke(Nothing, Nothing)
Me.BackColor = Color.Salmon
End Sub
Sub AddControl()
Dim c As New UserControl2
Me.Controls.Add(c)
c.Width = 350 : c.Height = 50
End Sub
End Class