本文介绍了VB9具有多个参数的新线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个新线程并发送多个参数以及一个委托以进行报告.

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

在VB8中,我总是讨厌这样做,因为它需要引入新的类/结构或委托.

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

在VB9中还有更好的方法吗?

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)

我对LINQ和Lambda不好,所以我希望有人会向我展示一些很酷的窍门.

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

推荐答案

可以将匿名函数传递给线程构造函数.

You could pass an anonymous function to the thread constructor.

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

但不幸的是,VB9中没有匿名子(它们将在VB10中-在C#中应该已经可以使用).

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

这篇关于VB9具有多个参数的新线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-10 21:56