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 HawaldarRank #110 · 20.2K reputationPosted Nov 17, 2022, 6:07 AM EST
we'll need more details is it not async?
why not create a thread
raj rajRank #5,629 · 292 reputationPosted Nov 18, 2022, 3:10 AM EST
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 HawaldarRank #110 · 20.2K reputationPosted Nov 19, 2022, 4:26 AM EST
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 rajRank #5,629 · 292 reputationPosted Nov 19, 2022, 10:21 AM EST
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
Amit MohantyRank #112 · 20K reputationPosted Nov 20, 2022, 11:49 PM EST
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.
Rajanikant HawaldarRank #110 · 20.2K reputationPosted Nov 21, 2022, 2:02 AM EST
why the need for a thread,what your trying todo, you can do as below
public void MethodName) { // Start the task executing: Task.Factory.StartNew(() => OtherMethod()); // Pass parameter if required //other code goes here as you require // Start the task executing: Task.Factory.StartNew(() => OtherMethod()); // Pass parameter if required //other code goes here as you require // Start the task executing: Task.Factory.StartNew(() => OtherMethod()); // Pass parameter if required } static string OtherMethod() { // }