我現在有一個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