110,539
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace CommonData.Forms
{
public partial class ProgressDialog : Form
{
private AdaProcess _Process;
public ProgressDialog(AdaProcess poProcess)
{
InitializeComponent();
this._Process = poProcess;
}
public void ResetStepInfo(string pcProcessName, string pcProcessInfo, int piProgressValue)
{
this.labProcessName.Text = pcProcessName;
this.labProcessPlan.Text = pcProcessInfo;
this.progressBar.Value = piProgressValue;
this.labStep.Text = piProgressValue + "%";
this.Text = pcProcessName;
}
private void btnCancel_Click(object sender, EventArgs e)
{
if (_Process != null)
{
if (AppMsg.ShowQuestionOkCancel("You will stop current thread! Are you sure?"))
{
_Process.Stop();
}
}
}
}
}
namespace CommonData.Forms
{
partial class ProgressDialog
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.progressBar = new System.Windows.Forms.ProgressBar();
this.labProcessName = new System.Windows.Forms.Label();
this.labProcessPlan = new System.Windows.Forms.Label();
this.btnCancel = new System.Windows.Forms.Button();
this.labStep = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// progressBar
//
this.progressBar.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.progressBar.ForeColor = System.Drawing.Color.Lime;
this.progressBar.Location = new System.Drawing.Point(5, 60);
this.progressBar.Name = "progressBar";
this.progressBar.Size = new System.Drawing.Size(459, 16);
this.progressBar.TabIndex = 0;
this.progressBar.Value = 100;
//
// labProcessName
//
this.labProcessName.Font = new System.Drawing.Font("SimSun", 10F);
this.labProcessName.Location = new System.Drawing.Point(6, 3);
this.labProcessName.Name = "labProcessName";
this.labProcessName.Size = new System.Drawing.Size(480, 30);
this.labProcessName.TabIndex = 1;
this.labProcessName.Text = "Name";
//
// labProcessPlan
//
this.labProcessPlan.Font = new System.Drawing.Font("SimSun", 10F);
this.labProcessPlan.Location = new System.Drawing.Point(6, 37);
this.labProcessPlan.Name = "labProcessPlan";
this.labProcessPlan.Size = new System.Drawing.Size(480, 17);
this.labProcessPlan.TabIndex = 2;
this.labProcessPlan.Text = "Info";
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(407, 79);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Size = new System.Drawing.Size(75, 23);
this.btnCancel.TabIndex = 4;
this.btnCancel.Text = "Cancel";
this.btnCancel.UseVisualStyleBackColor = true;
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// labStep
//
this.labStep.Location = new System.Drawing.Point(466, 61);
this.labStep.Name = "labStep";
this.labStep.Size = new System.Drawing.Size(25, 14);
this.labStep.TabIndex = 5;
this.labStep.Text = "00%";
this.labStep.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// ProgressDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(494, 108);
this.ControlBox = false;
this.Controls.Add(this.labStep);
this.Controls.Add(this.btnCancel);
this.Controls.Add(this.labProcessPlan);
this.Controls.Add(this.labProcessName);
this.Controls.Add(this.progressBar);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(500, 140);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(500, 140);
this.Name = "ProgressDialog";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Process Status";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ProgressBar progressBar;
private System.Windows.Forms.Label labProcessName;
private System.Windows.Forms.Label labProcessPlan;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.Label labStep;
}
}
using System;
using System.Collections.Generic;
using System.Text;
using CommonData.Forms;
using System.Threading;
using System.Windows.Forms;
namespace CommonData
{
public class AdaProcess
{
private delegate void ProgressFormInvoke(string pcProcessName, string pcProcessInfo, int piProgressValue);
private ProgressDialog _ProgressForm = null;
private Thread _Thread = null;
private System.Windows.Forms.Timer _ProcessTimer;
public AdaProcess()
{
_ProcessTimer = new System.Windows.Forms.Timer();
_ProcessTimer.Enabled = false;
_ProcessTimer.Interval = 200;
_ProcessTimer.Tick += new EventHandler(ProcessTimer_Tick);
}
public void Start(string pcProcessName, ThreadStart poThreadStart, bool plIsDialog)
{
string _ProcessName = pcProcessName;
if (_Thread != null)
{
return;
}
this._ProcessTimer.Enabled = true;
this._ProcessTimer.Start();
this._Thread = new Thread(poThreadStart);
this._Thread.SetApartmentState(ApartmentState.STA);
this._Thread.Start();
if (_ProgressForm == null)
{
_ProgressForm = new ProgressDialog(this);
_ProgressForm.Text = pcProcessName;
_ProgressForm.ResetStepInfo(pcProcessName, "", 0);
if (plIsDialog)
{
_ProgressForm.ShowDialog();
}
else
{
_ProgressForm.Show();
}
}
}
private void ProcessTimer_Tick(object sender, EventArgs e)
{
if (_Thread != null && !_Thread.IsAlive)
{
ResetProcessInfo("", "", 100);
_ProcessTimer.Stop();
_ProcessTimer.Enabled = false;
this.Stop();
}
}
public void ResetProcessInfo(string pcProcessName, string pcProcessInfo, int piProgressValue)
{
if (_ProgressForm != null)
{
ProgressFormInvoke loInvoke = new ProgressFormInvoke(_ProgressForm.ResetStepInfo);
_ProgressForm.Invoke(loInvoke, new object[] { pcProcessName, pcProcessInfo, piProgressValue });
}
}
public void Stop()
{
if (_Thread == null)
{
return;
}
try
{
_Thread.Abort();
_ProgressForm.Invoke(new MethodInvoker(_ProgressForm.Close));
}
catch (Exception)
{
}
finally
{
_ProgressForm = null;
_Thread = null;
}
}
public override string ToString()
{
return "AdaProcess";
}
}
}