我想配置我的線程爲後臺線程,爲什麼這個屬性在我的線程中失蹤?C#後臺線程屬性丟失
ThreadStart starter = delegate { openAdapterForStatistics(_device); };
new Thread(starter).Start();
public void openAdapterForStatistics(PacketDevice selectedOutputDevice)
{
using (PacketCommunicator statCommunicator = selectedOutputDevice.Open(100, PacketDeviceOpenAttributes.Promiscuous, 1000)) //open the output adapter
{
statCommunicator.Mode = PacketCommunicatorMode.Statistics; //put the interface in statstics mode
statCommunicator.ReceiveStatistics(0, statisticsHandler);
}
}
我有嘗試:
Thread thread = new Thread(openAdapterForStatistics(_device));
,但我有2編譯錯誤:
- 爲「System.Threading.Thread.Thread的最佳重載的方法匹配(系統.Threading.ThreadStart)'有一些無效參數
- 參數1:無法從'void'轉換爲'System.Threading.ThreadStar T」
,我不知道爲什麼
我認爲這是因爲你應該通過一個代表參數化函數。不是功能。在你的情況下啓動器。 – Juvil
嘗試'線程線程=新線程((()=> openAdapterForStatistics(_device));' –