|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Threading so restricted?Hi all,
Is it honestly true we can't start threads in VB.net 2005 if the sub or function has paratemeters like functioname(x1 as string, x2 as long) etc? This so restricts launching new threads. Global variables the only option? We can't use TLS before launching the thread right? Thanks a lot, Adam "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb: Check out the 'ParameterizedThreadStart' delegate.> Is it honestly true we can't start threads in VB.net 2005 if the sub or > function has paratemeters like functioname(x1 as string, x2 as long) etc? -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Hmmm, looking at some code this only seems to be doable if the sub is in a
class. Can't see anything if the sub is in a module, Adam Show quoteHide quote "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message news:%23fegqPRcGHA.1856@TK2MSFTNGP03.phx.gbl... > "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb: >> Is it honestly true we can't start threads in VB.net 2005 if the sub or >> function has paratemeters like functioname(x1 as string, x2 as long) etc? > > Check out the 'ParameterizedThreadStart' delegate. > > -- > M S Herfried K. Wagner > M V P <URL:http://dotnet.mvps.org/> > V B <URL:http://classicvb.org/petition/> Adam,
| Hmmm, looking at some code this only seems to be doable if the sub is in a Look again, the target of a Delegate can be in a Module, Structure, or a | class. Class. It can also be a shared method of a Class or Structure. For example: Public Module MainModule Private Sub Work(ByVal obj As Object) Dim parameter As String = TryCast(obj, String) ... do stuff based on parameter ... End Sub Public Sub Main() Dim worker As New Thread(AddressOf work) Dim parameter As String = "Something" worker.Start(parameter) ... wait for thread to finish ... End Sub End Module Notice that the sub is in a Module. If I needed to pass more then one parameter, I would consider passing a structure or a class... NOTE: 'ParameterizedThreadStart' is new to .NET 2.0 (VS 2005) -- Show quoteHide quoteHope this helps Jay B. Harlow [MVP - Outlook] ..NET Application Architect, Enthusiast, & Evangelist T.S. Bradley - http://www.tsbradley.net "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> wrote in message news:OWG5KWTcGHA.3344@TK2MSFTNGP03.phx.gbl... | Hmmm, looking at some code this only seems to be doable if the sub is in a | class. | | Can't see anything if the sub is in a module, | | Adam | | "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message | news:%23fegqPRcGHA.1856@TK2MSFTNGP03.phx.gbl... | > "Adam Honek" <AdamHo***@Webmaster2001.freeserve.co.uk> schrieb: | >> Is it honestly true we can't start threads in VB.net 2005 if the sub or | >> function has paratemeters like functioname(x1 as string, x2 as long) etc? | > | > Check out the 'ParameterizedThreadStart' delegate. | > | > -- | > M S Herfried K. Wagner | > M V P <URL:http://dotnet.mvps.org/> | > V B <URL:http://classicvb.org/petition/> | | Adam,
>This so restricts launching new threads. I don't think it's a big restriction. A common solution is to> >Global variables the only option? encapsulate the thread logic in a separate class, pass the "thread arguments" to a class constructor and store them in fields. No global variables needed. Mattias -- Mattias Sjögren [C# MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
How getting eventhandler attached to an event?
Simple word count Win32API - FindFirstFile() in VB.NET single to string problem Simple TCP communications examples My app as system process Variable with other variable Thread terminating instantly How to move the mouse around in vb.net Move emails (.msg files) between an Outlook inbox and a file direc |
|||||||||||||||||||||||