private bool bRetrun = false;

private ManualResetEvent meDo;

定义一个可以公用的静态变量

public class CommonData

{

    public static bool CloseFrom { get; set; }

}

 

主程序

Thread t = new Thread(new ThreadStart(TestDB));

meDo = new ManualResetEvent(false);

t.Start();

this.Hide();

if (new frmCloes().ShowDialog() == DialogResult.OK)

{

    this.Show();

}

meDo.WaitOne();

if (bRetrun) return;

 

把会卡死的程序放到方法里执行,比如TestDB

private void TestDB()

{

    if (!SysConfig.DBConnectionRing())

    {

        MessageBox.Show("选择的数据库连接失败,请检查!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Error);

        bRetrun = true;

    }

    else

    {

        bRetrun = false;

    }

    meDo.Set();

    CommonData.CloseFrom = true;

}

 

创建一个用于显示进程的窗体,做门面

在该窗体添加一个label和一个timer

private int RunCount = 0;

private void tmr_Tick(object sender, EventArgs e)

{

    if (CommonData.CloseFrom)

    {

        this.DialogResult = DialogResult.OK;

        Close();

    }

    else

    {

        RunCount++;

        if (RunCount > 10)

        {

            lblStatus.Text = "操作正在进行,请稍后";

            RunCount = 0;

        }

        lblStatus.Text += ".";

    }

}

相关文章:

  • 2021-09-08
  • 2021-06-23
  • 2021-04-05
  • 2021-04-26
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-01
  • 2022-02-06
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-11-24
相关资源
相似解决方案