I have set the following commands in my program and it started obviously
well :
Dim tr As New Thread(AddressOf HaalUitverkorenen)
tr.Priority = Threading.ThreadPriority.BelowNormal
tr.Start()
HaalUitverkorenen()
If tr.ThreadState = Threading.ThreadState.Running Then
tr.Abort()
End If
But I recieved quickly a exception because I put a string in a textbox
during the excecution of the sub HaalUitverkorenen :
the exception was telling :
Cross-thread operation not valid: Control 'TextBox1' accessed from a thread
other than the thread it was created on.
the textbox was placed in the beginning of the design on my form
what can I do?
I see two things that look like problems. First, you do tr.Start() on a
thread that will run at function HaalUitverkorenen(), and then your main
thread also calls functionHaalUitverkorenen(). This looks to me like you
will execute HaalUitverkorenen() twice, once on the new thread and once on
the main thread. In the code fragment, I think all you need is
Dim tr As New Thread(AddressOf HaalUitverkorenen)
tr.Priority = Threading.ThreadPriority.BelowNormal
tr.Start()
Second, there is a issue with windows where code that operates on some
controls has to execute on the same thread that the control execute on. So,
once you run HaalUitverkorenen() on its own thread, it cannot manipulate
forms and controls directly. There is a variety of written material on how
to solve this problem in the .net help documentation under the topic of
Invoke. The general idea is that your HaalUitverkorenen() thread can be made
to execute gui code on the gui main thread by appropriate function calls.