I am making my first attempt at using threads in an application, but on the line where I try to instantiate my thread I get the error ‘method name expected’. Here is my code :
private static List<Field.Info> FromDatabase(this Int32 _campId)
{
List<Field.Info> lstFields = new List<Field.Info>();
Field.List.Response response = new Field.List.Ticket
{
campId = _campId
}.Commit();
if (response.status == Field.List.Status.success)
{
lstFields = response.fields;
lock (campIdLock)
{
loadedCampIds.Add(_campId);
}
}
if (response.status == Field.List.Status.retry)
{
Thread th1 = new Thread(new ThreadStart(FromDatabase(_campId)));
th1.Start();
}
return lstFields;
}
ThreadStart constructor only accepts method name. You’re executing the method there.
Change it to
Thread th1 = new Thread(new ThreadStart(FromDatabase));However that would be incorrect since FromDatabase method appears to be taking parameter while ThreadStart expects method with no parameters so you should be using instead ParameterizedThreadStart
Read the following article for more detail: http://www.dotnetperls.com/parameterizedthreadstart