Opening a different form inside running form without interrupting execution of the !st form

后端 未结 1 655
误落风尘
误落风尘 2021-01-29 05:46

I have a windows form application which is supposed to do multiple tasks on a system like taking snapshot of the desktop, finding free disk space, popping up a message, creating

相关标签:
1条回答
  • 2021-01-29 06:31

    One very simple solution is to display your forms modeless instead of modally. That is, instead of calling form.ShowDialog(), call form.Show().

    This solution implies, however, that you cannot use System.Windows.Forms.MessageBox.Show(…), since these message boxes are always modal. You would have to create your own message box form that looks like MessageBox (but can be shown modeless, like other Forms).

    Another solution is indeed to created a separate STA thread for each form, and call Application.Run(form); on that thread. You get better separation — that is, only forms on the same thread can block one another, and if each form gets a separate thread, blocking is very unlikely to occur. The major disadvantage (next to lots of probably unnecessary threads) is that it's going to be somewhat trickier if your forms need to interact.

    0 讨论(0)
提交回复
热议问题