using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
namespace Monitor.Class
{
/// <summary>
/// 异步操作
/// </summary>
public class CWorker
{
/// <summary>
/// 对象
/// </summary>
private BackgroundWorker backgroundWorker;
/// <summary>
/// 后台执行的操作
/// </summary>
public Action BackgroundWork { get; set; }
/// <summary>
/// 后台任务执行完毕后事件
/// </summary>
public event EventHandler<BackgroundWorkerEventArgs> BackgroundWorkerCompleted;
private BackgroundWorkerEventArgs _eventArgs;//异常参数
/// <summary>
/// 构造
/// </summary>
public CWorker()
{
_eventArgs = new BackgroundWorkerEventArgs();
backgroundWorker = new BackgroundWorker();
backgroundWorker.WorkerReportsProgress = true;
backgroundWorker.WorkerSupportsCancellation = true;
backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);
backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);
}
/// <summary>
/// 开始工作
/// </summary>
public void BegionWork()
{
if (backgroundWorker.IsBusy)
return;
backgroundWorker.RunWorkerAsync();
}
/// <summary>
/// 工作
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
if (BackgroundWork != null)
{
try
{
BackgroundWork();
}
catch (Exception ex)
{
_eventArgs.BackGroundException = ex;
}
}
}
/// <summary>
/// 完成
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (this.BackgroundWorkerCompleted != null)
{
this.BackgroundWorkerCompleted(null, _eventArgs);
}
}
}
/// <summary>
/// 事件
/// </summary>
public class BackgroundWorkerEventArgs : EventArgs
{
/// <summary>
/// 后台程序运行时抛出的异常
/// </summary>
public Exception BackGroundException { get; set; }
}
}
namespace Monitor
{
/// <summary>
/// Splash.xaml 的交互逻辑
/// </summary>
public partial class Splash : Window
{
MainWindow m_MainWindow = null;//主窗口
CWorker m_Work = null;//任务
public Splash()
{
InitializeComponent();
m_MainWindow = new MainWindow();//创建主窗口对象
m_Work = new CWorker();
m_Work.BackgroundWork = this.ProcessDo;
m_Work.BackgroundWorkerCompleted += new EventHandler<BackgroundWorkerEventArgs>(m_Work_BackgroundWorkerCompleted);
}
/// <summary>
/// 进度提示
/// </summary>
public void ProcessDo()
{
m_MainWindow.InitData(this);
}
/// <summary>
/// 移动
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
/// <summary>
/// 窗口加载
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
m_Work.BegionWork();
}
/// <summary>
/// 执行完成
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
void m_Work_BackgroundWorkerCompleted(object sender, BackgroundWorkerEventArgs e)
{
m_MainWindow.Show();
this.Close();
}
/// <summary>
/// 赋值
/// </summary>
/// <param name="text"></param>
private delegate void SetProcessLabelDelegate(string text, double processValue);
public void SetProcessValue(string text, double processValue)
{
if (!Dispatcher.CheckAccess())
{
Dispatcher.Invoke(DispatcherPriority.Send, new SetProcessLabelDelegate(SetProcessValue), text, processValue);
return;
}
this.lblProcess.Content = text;
this.ProgressControlRealValue.Value = processValue;
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有