i want to configure my Thread to be background thread, why this property missing in my Thread ?
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);
}
}
i have try:
Thread thread = new Thread(openAdapterForStatistics(_device));
but i have got 2 compilation errors:
- The best overloaded method match for ‘System.Threading.Thread.Thread(System.Threading.ThreadStart)’ has some invalid arguments
- Argument 1: cannot convert from ‘void’ to ‘System.Threading.ThreadStart’
and i don’t know why
About the background thing, I don’t see how you expect to set it since you’re not keeping a reference to the thread. Should look like this:
This
won’t work because you’re supposed to pass in a method that takes
objectas parameter, while you’re actually passing the result of a method call. So you could do this:and: