PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Re: Manipulating controls created by another thread
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Re: Manipulating controls created by another thread
![]() |
Re: Manipulating controls created by another thread |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Pass in the for instance when you create the worker, i.e. :
Dim MyWorker As New Worker ( Me ) then invoke on the instance. Also make sure Button1 is not returning a "dialogresult". If it is, it might destroy the form when it is clicked which will result in the handle being unavailable. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Here, also as branco says Please note that if you close the form beforethe thread has completed, you will get the handle error. I have introduced a delay in the thread so you can see it in operation - and am using "Invoke" rather than "BeginInvoke". Public Class Form1 Delegate Sub DisplayStatus(ByVal msg As String) Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim MyWorker As New Worker(Me) Dim t As New Threading.Thread(AddressOf MyWorker.counter) t.Start() End Sub Public Sub Status(ByVal msg As String) TextBox1.Text = msg End Sub End Class Public Class Worker Private m_Form As Form1 Public Sub New(ByVal theForm As Form1) m_Form = theForm End Sub Public Sub counter() Dim i As Integer Dim theDelegate As New Form1.DisplayStatus(AddressOf m_Form.Status) For i = 0 To 10000 m_Form.Invoke(theDelegate, New Object() {i.ToString}) Threading.Thread.Sleep(100) Next End Sub End Class "Jens" <Jens@discussions.microsoft.com> wrote in message news:2768AEED-A9A1-4E17-A46A-1B50E215E92F@microsoft.com... > This seems to be the same problem, but they haven't found a solution, yet: > http://groups.google.de/group/micro...8bd026d36a33fa8 |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

Please note that if you close the form before
