📄 form2.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace UseThreadApp
{
/// <summary>
/// Form2 的摘要说明。
/// </summary>
public class Form2 : System.Windows.Forms.Form
{
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Label label1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form2()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.label1 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(10, 80);
this.progressBar1.Maximum = 1000;
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(272, 23);
this.progressBar1.Step = 1;
this.progressBar1.TabIndex = 1;
//
// label1
//
this.label1.Location = new System.Drawing.Point(8, 24);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(120, 24);
this.label1.TabIndex = 3;
this.label1.Text = "运算线程:";
//
// Form2
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 141);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label1,
this.progressBar1});
this.Name = "Form2";
this.ResumeLayout(false);
}
#endregion
public void MyCalculate()
{ //无限循环,模拟大量计算任务
while(true)
{
for (int i=0;i<1000;i++)
{
for (int j=0;j<1000;j++)
{
double k = 123.456;
}
}
//修改ProgressBar的进度,表示运算在进行
progressBar1.Value %= progressBar1.Maximum;
progressBar1.Value ++;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -