Spawn Multiple Threads for work then wait until all finished

后端 未结 12 1559
遇见更好的自我
遇见更好的自我 2020-11-28 01:46

just want some advice on \"best practice\" regarding multi-threading tasks.

as an example, we have a C# application that upon startup reads data from various \"type

12条回答
  •  隐瞒了意图╮
    2020-11-28 02:07

    If you're not on .NET 4.0 then you can use a List, one for each thread and Wait for them to be Set. To wait on multiple threads you could consider using WaitAll but watch out for the limit of 64 wait handles. If you need more than this, you can just loop over them and wait for each one individually.

    If you want a faster startup exprience, you probably don't need to wait for all the data to be read during startup. Just display the GUI and any information that is missing can be shown greyed out with some sort of "Updating..." icon or similar. When the information comes in, just fire an event to update the GUI. There could be many operations that the user can begin to perform even before all the data from all tables is read in.

提交回复
热议问题