处理开始时在 c#.net 中打开新窗口

发布于 2024-10-26 03:37:34 字数 135 浏览 1 评论 0原文

我正在 c#.net 中开发一个项目,一个密码生成器。我的问题是,当生成密码时,会打开一个新的窗口窗体并显示“请稍候”。在处理完成之前,我的主表单处于非活动状态。我已经使用了 showdialog,它可以工作,但它会停止我的主表单处理。帮帮我,我能做什么?

I'm working on a project in c#.net, a password generator. My problem is that when the password is generated a new window form opens and shows "please wait". My main form is inactive until processing is complete. I already use showdialog, which works, but it stops my main form processing. Help me, what can I do ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怎樣才叫好 2024-11-02 03:37:34

如果没有看到任何代码,那么提供帮助有点困难..但我为您制作了整个流程的一些工作示例:

    BackgroundWorker worker;
    Form dialogForm;

    private void buttonGeneratePassword_Click( object sender, EventArgs e )
    {
        worker = new BackgroundWorker();
        worker.DoWork += new DoWorkEventHandler( worker_DoWork );
        worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler( worker_RunWorkerCompleted );
        worker.RunWorkerAsync();

        dialogForm = new Form(); // dispay your dialog
        dialogForm.ShowDialog();
    }

    void worker_RunWorkerCompleted( object sender, RunWorkerCompletedEventArgs e )
    {
        // password generated.. close dialog form
        dialogForm.Close();
    }

    void worker_DoWork( object sender, DoWorkEventArgs e )
    {
        // put generate password code here
        Thread.Sleep( 1000 ); // delete this line - it is only for testing flow without password generation code
    }

希望它对您有帮助..

It is a bit difficult to help if don't see any code.. but I make some working sample for you with entire flow:

    BackgroundWorker worker;
    Form dialogForm;

    private void buttonGeneratePassword_Click( object sender, EventArgs e )
    {
        worker = new BackgroundWorker();
        worker.DoWork += new DoWorkEventHandler( worker_DoWork );
        worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler( worker_RunWorkerCompleted );
        worker.RunWorkerAsync();

        dialogForm = new Form(); // dispay your dialog
        dialogForm.ShowDialog();
    }

    void worker_RunWorkerCompleted( object sender, RunWorkerCompletedEventArgs e )
    {
        // password generated.. close dialog form
        dialogForm.Close();
    }

    void worker_DoWork( object sender, DoWorkEventArgs e )
    {
        // put generate password code here
        Thread.Sleep( 1000 ); // delete this line - it is only for testing flow without password generation code
    }

Hope it help you..

同展鸳鸯锦 2024-11-02 03:37:34

使用 Show() 而不是 ShowDialog()

Use Show() instead of ShowDialog()

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文