Reputation: 27265
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.
Upvotes: 1
Views: 1611
Reputation: 49218
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).
Upvotes: 2
Reputation: 11054
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.
Upvotes: 0