Creating a execution queue by using Task.ContinueWith?

后端 未结 3 760
旧巷少年郎
旧巷少年郎 2021-02-04 16:32

I have several actions that I want to execute in the background, but they have to be executed synchronously one after the other.

I was wondering if it\'s a good idea to

3条回答
  •  不思量自难忘°
    2021-02-04 17:17

    This should work as designed (using the fact that TPL will schedule the continuation immediately if the corresponding task already has completed).

    Personally in this case I would just use a dedicated thread using a concurrent queue (ConcurrentQueue) to draw tasks from - this is more explicit but easier to parse reading the code, especially if you want to find out i.e. how many tasks are currently queued etc.

提交回复
热议问题