We want to call start method 4 times but we do not want to create thread object for each time. Is it possible to create one object of thread and call same method 4 times.
we tried different ways but new initialization require for every time when we are calling method.
Rajanikant HawaldarPosted Nov 21, 2022, 7:02 AM
why the need for a thread,what your trying todo, you can do as below
Amit MohantyPosted Nov 21, 2022, 4:49 AM
You cannot run a thread more than once. If you want to reuse threads, then use the ThreadPool. A thread pool is a pool of worker threads which are always running. Those threads then normally take tasks from a list, execute them, then try to take the next task. If there's no task, the thread will wait. It will automatically handle your "work" and pushing it into a free thread, scheduling, and queuing tasks that can't be run because you're using all of the available threads.
raj rajPosted Nov 19, 2022, 3:21 PM
not every time call in a sequence some other function call in between I gave just an example.
all 4 methods call different time and different sequence
Rajanikant HawaldarPosted Nov 19, 2022, 9:26 AM
Why don't you use Task.Run() and use a loop in there to run the thing you want 4 times?
It's not really necessary to create threads yourself..you know. This will run it in a thread pool
raj rajPosted Nov 18, 2022, 8:10 AM
We want to call start method 4 times but we do not wan to create thread for each time.
Is it possible to create one object of thread and call same method 4 times.
Thread thr1 = new Thread(obj.value);
thr1.Start();
// doing some operaton
Thread thr2 = new Thread(obj.value);
thr2.Start();
// doing some operaton
Thread thr3 = new Thread(obj.value);
thr3.Start();
// doing some operaton
Thread thr4 = new Thread(obj.value);
thr4.Start();
// doing some operaton
but we do not want to inialize every time
Rajanikant HawaldarPosted Nov 17, 2022, 11:07 AM
we'll need more details is it not async?
why not create a thread