Background Threads in C#

后端 未结 3 788
清歌不尽
清歌不尽 2021-01-05 17:52

I am new to C#.I learnt that normally all threads are foreground until unless you explicitly specify it as \"background\" thread using IsBackGround= true .

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-05 18:24

    1) What is the advantage of keeping a thread as background thread?

    The Advantage is that a Background Thread doesn't stop the Program from terminating. In a large Application it could be a bit hard to deactivate all threads if you want to quit the Application.

    Apart from Join() could i use other techniques to keep the main thread wait?

    If yo want to make the Main program wait why do you make the thread a background thread in the first place then??? Besides of Join() you could use a EventWaitHandle or Monitor to make the main method wait.

提交回复
热议问题