Use await(async) methods inside BatchJob

BatchJob.StartNew(async(batchJob) => {
     for (var i = 0; i < 10; i++)
    {
        x.Enqueue(() => SendEmail(i));

       await doSomework(i)
    }
}

If i call async method inside batchjob only back ground job will be created.

BatchJob.StartNew((batchJob) => {
     for (var i = 0; i < 10; i++)
    {
        x.Enqueue(() => SendEmail(i));

       doSomework(i).wait()
    }
}

but when i use .wait() method it is working.

I mean only One back ground job will be created

I know it’s late but i answer for further knowledge:

The problem is that that BatchJob.StartNew(…) accept an Action as parameter (not a Function).
An async Action is not awaited, so the startNew Task end after firing the async Action (async(batchJob)).

The second code is working not because you use .wait(); instead of await but because the main action is sincronous.

J-