I have function called from a different thread. And it creats a list of objects and now I need to return it to the main thread. How do I do this? Or can I just create the list of objects in the main thread and manipulate it in the separate thread?
Main thread
Thread t = new Thread(Quote);
t.Start(workList);
private void Quote(object obj)
{
List<Work> works = new List<Work>();
works = (List<Work>)obj;
foreach (Work w in works)
{
//do something w
}
//return works to main thread
}
You can share the List resource across your thread but you’ll be responsible about the synchronization, List objects are not thread safe.
Use this snippet of code