zoukankan      html  css  js  c++  java
  • 关于Thread的实例

    代码
    ///调用Wait类,并显示等待状态
    private void button1_Click(object sender, EventArgs e)
    {
    ////Wait类
    Wait f = new Wait();
    this.Hide();//隐藏主窗体
    f.Show("加载数据中....");//显示等待窗体
    Thread.Sleep(900);
    f.Show(
    "登录中....");
    Thread.Sleep(
    900);
    f.Show(
    "加载中....");
    Thread.Sleep(
    900);
    f.Close();
    //关闭等待窗体
    this.Show();//显示主窗体
    }

    ////Wait类
    using System;
    using System.Threading;
    using System.Text;
    using System.Windows.Forms;

    namespace WinFormWait
    {
    partial class Form2 : Form
    {
    public Form2()
    {
    InitializeComponent();

    }
    /// <summary>
    /// 设置显示信息
    /// </summary>
    /// <param name="message"></param>
    public void SetMes(string message)
    {
    this.label1.Text = message;
    }
    }
    public class Wait
    {
    /// <summary>
    /// Thread对像
    /// </summary>
    private Thread thread = null;
    /// <summary>
    /// Form2对像
    /// </summary>
    private Form2 f = null;
    /// <summary>
    /// 默认构造函数
    /// </summary>
    public Wait()
    {
    ///实例化
    f = new Form2();
    ///创建线程并显示Form2窗体
    thread = new Thread(new ThreadStart(delegate { f.ShowDialog(); }));
    }
    /// <summary>
    /// 显示窗体
    /// </summary>
    /// <param name="message"></param>
    public void Show(string message)
    {
    f.Show();
    //弹出窗体
    f.SetMes(message);///设置信息
    f.Refresh();//重新绘制窗体
    }
    /// <summary>
    /// 关闭窗体并停止线程
    /// </summary>
    public void Close()
    {
    f.Close();
    try
    { thread.Abort(); }
    catch { }
    }
    }
    }
  • 相关阅读:
    002-pythn基础-循环、编码
    001-python3 初识
    confluence6.x安装
    python+ffmpeg切割视频
    Elasticsearch6.x和Kibana6.x的安装
    django基础
    CDH的完全离线安装(ubuntu16)
    python之旅十【第十篇】paramiko模块
    解决 MariaDB无密码就可以登录的问题
    切割日志(mysql,nginx,php tomcat)使用logrotate
  • 原文地址:https://www.cnblogs.com/server126/p/1911640.html
Copyright © 2011-2022 走看看