E
E
estry2020-05-03 17:22:04
C++ / C#
estry, 2020-05-03 17:22:04

How to run a method in multithread?

Hello. How to run a method in multithread?

public async Task Run()
{
  if (!GetData())
  {
    //уведомление
    return;
  }

  if (!await OkLion())
  {
    //уведомление
    return;
  }

  await GoVelo();

  SaveHuman();

}


Tried to run in 9 threads like this:
var tasks = Enumerable.Range(1, 10)
                  .Select((x) =>
                  {
                      Bego bego = new Bego();
                      return bego.Run();
                  })
                  .ToArray();

await Task.WhenAll(tasks);

But the threads are executed in turn. I need the simultaneous launch of all 9 threads. How to do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Yudakov, 2020-05-03
@estry

return Task.Run(bego.Run());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question