WaitingFormHelper

本文介绍了一个名为WaitingFormHelper的类,该类用于在执行指定操作时显示等待窗体。通过提供Action委托和提示消息作为参数,可以方便地在应用程序中使用此辅助类来展示加载界面。
using Lba_Ciac;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Lbb.Cx.Ciac.Utility
{
    public class WaitingFormHelper
    {
        private Loading waitingForm = null;

        private Action _method = null;

        private WaitingFormHelper(Action method, string message)
        {
            this._method = method;
            this.waitingForm = new Loading();
            this.waitingForm.Text = message;
            this.waitingForm.StartPosition = FormStartPosition.CenterParent;
            this.waitingForm.Shown += new EventHandler(this.waitingForm_Shown);
        }
        public static void ShowWaitingForm(Action method, string message)
        {
            WaitingFormHelper waitingFormHelper = new WaitingFormHelper(method, message);
            waitingFormHelper.waitingForm.ShowDialog();
        }

        private void waitingForm_Shown(object sender, EventArgs e)
        {
            try
            {
                this._method.BeginInvoke(new AsyncCallback(this.callBack), null);
            }
            catch (System.ObjectDisposedException)
            {
                return;//如果主界面已经退出了,那线程也退出好了。
            }
        }

        private void callBack(IAsyncResult ar)
        {
            if (this.waitingForm != null && !this.waitingForm.IsDisposed)
            {
                this.waitingForm.Invoke(new Action(delegate
                {
                    this.waitingForm.Close();
                }));
            }
        }
    }
}

  

转载于:https://www.cnblogs.com/XuPengLB/p/7866445.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值