• Welcome to Valhalla Legends Archive.
 

[VB.Net] Cross-Threading question.

Started by Spilled, December 01, 2008, 07:46 PM

Previous topic - Next topic

Spilled

Okay I will have a class that will have 2 threads sent to it. My question is what will be the best way for those threads to access a function that accesses 2 of my controls(listbox and a trackbar) that is in my form1 class without crossthreading?

Ex:(form1.vb)

public function INeedToAccessThis() as string
'do stuff with listbox
'do stuff with trackbar
return infoneeded
end function

ex: Class1

public sub ThreadProc()
'need to call form1.INeedToAccessThis
end sub

MyndFyre

All Controls implement the ISynchronizeInvoke interface.  Where you need to call ThreadProc, you might code:

If Form1.InvokeRequired Then
    Form1.Invoke(AddressOf ThreadProc)
Else
    ThreadProc()
End If
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Spilled