我现在有一个Windows窗体应用程序,我想创建一个新线程并在另一个接受输入的类上运行一个方法。C#中的线程问题
例如
public partial class Form1: Form {
SerialPort serialInput;
// I want to create a new thread that will pass the parameter serialInput into the method
// SMSListener on another class and run the method contionously on the background.
}
class SMS
{
public void SMSListener(SerialPort serial1)
{
serial1.DataReceived += port_DataRecieved;
}
private void port_DataRecieved(object sender, SerialDataReceivedEventArgs e)
{
// Other codes
}
}
如何在C#中执行此?我在网上看到了很多例子,他们中的大多数都在同一个类上运行方法,没有参数,但没有一个适合我的要求。
看一看[BackgroundWorker的类(http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx) – digEmAll 2011-05-17 08:35:30
已经尝试过,但还是搞清楚如何得到我想要的结果。 – abduls85 2011-05-17 08:43:25