Lets say my form1 needs to perform some operation and I designed a custom
control that will show the user some information about the operation. Well
For the sake of seamlessness I would rather have that control added to the
control list of form1 and have it run on its own thread so that the user can
see the updates happening, and the operations going on in form1 will not be
effected.
My form1 is docked to the top of the users screen, so I do not have to worry
about the user being able to move it or interact with it in any way while
the operation is underway.
while f is the Form reference, and YourMethod is the method adding the
control. However, I'd raise a neutral event instead that is handled by the
Form and excutes the line above (replace 'f' by 'Me'). One shouldn't care
about the UI in a worker thread (IMO).
Yeah that doesn't work and I know it's not what you told me to do, lol I'm
sorry. Its as if I am wanting to do this.
I have form1, it is going to do some calculations for a bit, I cannot escape
that fact as form1 is my main application form. What I want to do is create
a new thread that will add a control to form1 (that covers the entire form)
and display a bussy animation. Problem is VB wont let me add a control to a
form on a different thread. I'm certain what you gave me will work I guess
I just do not understand what I am supposed to do.
This is my code, Mainform is essentially form1 as described above.
'simple code to display bussy notification
Public mrg_p As wait
Private t As Threading.Thread
Public Sub show_bussy()
t = New Threading.Thread(AddressOf bussy)
t.Start()
End Sub
Private Sub bussy()
If mrg_p IsNot Nothing Then mrg_p.Dispose()
mrg_p = New wait
'MainForm.Controls.Add(mrg_p)
' f.Invoke(New MethodInvoker(AddressOf f.YourMethod))
MainForm.Invoke(New MethodInvoker(AddressOf MainForm.Controls.Add))
MainMarque.Visible = False
With mrg_p
.Top = 0
.Left = 0
.Dock = DockStyle.Fill
End With
MakeWindowAlwaysTop(mrg_p.Handle.ToInt32)
mrg_p.Show()
mrg_p.Visible = True
End Sub
Well I tried this...Which worked but it defeats the purpose because it
places the control under mainform's thread instead of the new one I made and
the animation doesn't run, also the thread abort command never fires.
Private Sub bussy()
If mrg_p IsNot Nothing Then mrg_p.Dispose()
mrg_p = New wait
'MainForm.Controls.Add(mrg_p)
' f.Invoke(New MethodInvoker(AddressOf f.YourMethod))
MainForm.Invoke(New MethodInvoker(AddressOf add_bussy))
MainMarque.Visible = False
With mrg_p
.Top = 0
.Left = 0
.Dock = DockStyle.Fill
End With
MakeWindowAlwaysTop(mrg_p.Handle.ToInt32)
mrg_p.Show()
mrg_p.Visible = True
End Sub
Private Sub add_bussy()
MainForm.Controls.Add(mrg_p)
End Sub
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.