开发者

How do I cleanly pause a thread until another thread completes or a value is changed

Using C#: I have a class "MsgBox", a special Message Box formatted to my application. It runs on an instance, the point was so that when I called: 'new MsgBox("Message Text");' it would pause the calling thread until the form gets a response/closes or whatever. I tried r开发者_开发知识库unning the Form on another thread and using Thread.Suspend()/Resume() and it freezes the whole computer for a two or three seconds, then works fine. Same with Thread.Join(). Is there a more efficient way to hold the thread?


You can use Form.ShowDialog 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 dialog box can be assigned one of the values of the DialogResult enumeration by assigning it to the DialogResult property of a Button on the form or by setting the DialogResult property of the form in code. This value is then returned by this method. You can use this return value to determine how to process the actions that occurred in the dialog box. For example, if the dialog box was closed and returned the DialogResult.Cancel value through this method, you could prevent code following the call to ShowDialog from executing.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜