C#如何暂停执行? [英] C# How can I pause execution?

查看:813
本文介绍了C#如何暂停执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

情况就是这样.
我有一个表格,上面有一个按钮.当用户单击我要打开新表单的按钮时,用户从该表单中选择某项内容,接受选择,然后使用先前选择的项目继续执行主表单.

我在想线程,但是怎么想呢?

The situation is this.
I have a form and on it a button. When the user clicks the button I want a new form to open, the user to select something from that form,accept the selection, and then the main form to continue execution using the item previously selected.

I''m thinking threads, but how?

推荐答案

如果您要这样做,则不需要执行任何线程阻塞.您需要做的就是以模态对话框的形式打开新窗体,该对话框将暂停对调用代码的执行,直到对话框返回为止.这是一个典型的流程:
If you want to do this, you don''t need to do any thread blocking. All you need do is open the new form as a modal dialog, which pauses execution on the calling code until the dialog returns. Here''s a typical flow:
private void ShowMyDialog()
{
  using (MyDialog dialog = new MyDialog())
  {
    if (dialog.ShowDialog() == DialogResult.OK)
    {
      MessageBox.Show(dialog.UserEnteredValue);
    }
  }
}


这篇关于C#如何暂停执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆