If i have a method like this
private void LoadModel(List<object> filenames)
{
}
and want to run this method in thread i make this
loadingThread = new ParameterizedThreadStart(LoadModel)
but give me error
how to solve this problem ?
No overload for 'LoadModel' matches delegate 'System.Threading.ParameterizedThreadStart'
Another way to solve your problem that allows your method to still have the type of the parameter that you want is to use a lambda expression like this:
Thread thread = new Thread(() => LoadModel(list));
Where list
is the parameter value that you want to pass.
This delegate is defined as
public delegate void ParameterizedThreadStart(object obj)
You have to change your method declaration to match it:
private void LoadModel(object filenames)
and cast filenames
to List
in the method.
To create and start the thread use
Thread loadingThread = new Thread(LoadModel);
loadingThread.Start(filenames);
Instead of creating your own threads, consider using Tasks or ThreadPool.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With