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;
}
Advantages of Thread Threads minimize the context switching time. Use of threads provides concurrency within a process. Efficient communication. It is more economical to create and context switch threads.
Starvation describes a situation where a thread is unable to gain regular access to shared resources and is unable to make progress. This happens when shared resources are made unavailable for long periods by "greedy" threads.
Multithreading is the ability of a program or an operating system to enable more than one user at a time without requiring multiple copies of the program running on the computer. Multithreading can also handle multiple requests from the same user.
Argh I hate it when people say "don't use ThreadGroup". It's like saying "don't use Threads". A thread has a ThreadGroup, there's no getting around that, so unless you want to have a program with no threads, you are using ThreadGroups. I agree we need a question to address when, how and why not to use them.
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
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