views:

528

answers:

4

I'm trying to create a new thread and send multiple parameters as well as a delegate to report back.

In VB8 I always hate to do this because it requires either introducing a new class/structure or a delegate.

Is there any better way to do this in VB9 ?

I'm looking for a solution something like this :

   Dim Th As New Thread(AddressOf DoStuff)
   Th.Start(param1, param2, AddressOf ReportStatus)

I'm not good with LINQ and Lambda, so I'm hopping that someone will show me some cool trick to do this.

+1  A: 

Nope. Nothing new in VB9.

Boo
A: 

Maybe you're already familiar with this, but depending on your application, using ThreadPool can be useful and easy. I don't know much about sending parameters with ThreadPool.QueueUserWorkItem, but this page seems to give a good tutorial involving lambda expressions and anonymous types. It's in C# but I'm sure it would translate to VB.

hypoxide
Actually I'm trying to something similar but that page is in C# (I can read C# and convert except Linq and lambad :) ). Also I'm not sure how much of it can be applied to VB.NET
dr. evil
+1  A: 

Hi,

You could pass an anonymous function to the thread constructor.

Dim Th = New Thread(Sub() DoStuff(param1, param2, AddressOf ReportStatus))

but unfortunately there are no anonymous subs in VB9 (they will be in VB10 - In C# this should already work).

Dario
OK, I thought it was possible in VB9, shame on MS
dr. evil
Shame on MS? It's people like you that give MS a bad name. Microsoft has consistantly improved the VB and C# languages with every single release. Shame on YOU for not giving credit where credit is deserved.
Boo
A: 

"Shame on MS? It's people like you that give MS a bad name. Microsoft has consistantly improved the VB and C# languages with every single release. Shame on YOU for not giving credit where credit is deserved. – Boo"

...That's a masterpiece. MS have more important things (like giving away their development tools for free to those who want to debvelop MS apps for the MS OS) than trivial nonsense like this. MS would revel in benefits from PD tools to develop software for THEIR platform. Bad press is the least of MS's worries, irrespective of the alleged rubbish they release.

Droid 73