Answer the question
In order to leave comments, you need to log in
How to correctly call ThreadPool and put a method in it?
There is a void type method that accepts a sheet
private void add(List<Data> Data)
{
var loaddata = new LoadData();
loaddata.add(Data);
}
void SomeMethod() {
new Task(() =>
{
add(DataList);
}).Start();
}
Answer the question
In order to leave comments, you need to log in
All asynchronous operations where a Task is involved are performed in the ThreadPool.
ThreadPool - There can only be one per application.
"How can I do the same only through the ThreadPool?" - You are already using it.
I haven't worked with it for a long time, but something like this should work
ThreadPool.QueueUserWorkItem(new WaitCallback(add), DataList);
Use async-await constructs. Direct access to Thread & ThreadPoll is a bit deprecated with the release of .Net 4.5.
async void Add(List<Data> Data)
{
await Task.Run(() =>
{
var loaddata = new LoadData();
loaddata.add(Data);
});
}
async Task Add(List<Data> Data)
{
await Task.Run(() =>
{
var loaddata = new LoadData();
loaddata.add(Data);
});
}
await Add(new List<Data>());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question