why does form.showdialog() works and form.show() doesn't in the following code

前端 未结 2 679
旧巷少年郎
旧巷少年郎 2021-01-28 21:22

In the following piece of code I have a watcher that look if file has changed and if it has changed I show the changed information on a form but if i use form.Show() for this it

2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-28 22:01

    ShowDialog halts the program flow, until you close the form, whereas Show displays the form and continues with the program flow.

    Form.ShowDialog - MSDN

    You can use this method to display a modal dialog box in your application. When this method is called, the code following it is not executed until after the dialog box is closed.

    The problem is because of the using block. ShowDialog method is blocking the program flow until the form is closed, because of that using block will not terminate. Show on the other hand returns control to the next line immediately and since you created the form object inside the using block, it will not be visible outside of the block. That is why you get your form stuck.

提交回复
热议问题