⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 线程池实例,1.1版本,用于代替.net自带线程池
💻 CS
📖 第 1 页 / 共 3 页
字号:
using System;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;

using Amib.Threading;

namespace TestSmartThreadPool
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button btnStart;
		private System.Windows.Forms.Button btnStop;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label lblThreadInUse;
		private System.Windows.Forms.Label label7;
		private System.Windows.Forms.NumericUpDown spinIdleTimeout;
		private System.Windows.Forms.NumericUpDown spinMaxThreads;
		private System.Windows.Forms.NumericUpDown spinMinThreads;
		private System.Windows.Forms.NumericUpDown spinInterval;
		private System.Windows.Forms.Timer timerPoll;
		private System.ComponentModel.IContainer components;
		private System.Windows.Forms.Label lblThreadsInPool;
		private System.Windows.Forms.Label label6;
		private System.Windows.Forms.NumericUpDown spinConsumingTime;

		private SmartThreadPool _smartThreadPool;
		private IWorkItemsGroup _workItemsGroup;
		private System.Windows.Forms.Label lblWaitingCallbacks;
		private System.Windows.Forms.Label label9;
		private System.Windows.Forms.Label label8;
		private System.Windows.Forms.Label lblWorkItemsGenerated;
		private bool running;
		private long workItemsGenerated;
		private System.Windows.Forms.Label label10;
		private System.Windows.Forms.Label lblWorkItemsCompleted;
		private UsageControl.UsageControl usageThreadsInPool;
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.GroupBox groupBox3;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox4;
		private UsageControl.UsageHistoryControl usageHistorySTP;
		private System.Diagnostics.PerformanceCounter pcActiveThreads;
		private System.Diagnostics.PerformanceCounter pcInUseThreads;
		private System.Diagnostics.PerformanceCounter pcQueuedWorkItems;
		private System.Diagnostics.PerformanceCounter pcCompletedWorkItems;
		private long workItemsCompleted;

		public Form1()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (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.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
			this.btnStart = new System.Windows.Forms.Button();
			this.btnStop = new System.Windows.Forms.Button();
			this.label1 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.label4 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.lblThreadsInPool = new System.Windows.Forms.Label();
			this.label5 = new System.Windows.Forms.Label();
			this.spinIdleTimeout = new System.Windows.Forms.NumericUpDown();
			this.spinMaxThreads = new System.Windows.Forms.NumericUpDown();
			this.spinMinThreads = new System.Windows.Forms.NumericUpDown();
			this.spinInterval = new System.Windows.Forms.NumericUpDown();
			this.lblThreadInUse = new System.Windows.Forms.Label();
			this.label7 = new System.Windows.Forms.Label();
			this.timerPoll = new System.Windows.Forms.Timer(this.components);
			this.spinConsumingTime = new System.Windows.Forms.NumericUpDown();
			this.label6 = new System.Windows.Forms.Label();
			this.lblWaitingCallbacks = new System.Windows.Forms.Label();
			this.label9 = new System.Windows.Forms.Label();
			this.label8 = new System.Windows.Forms.Label();
			this.label10 = new System.Windows.Forms.Label();
			this.lblWorkItemsGenerated = new System.Windows.Forms.Label();
			this.lblWorkItemsCompleted = new System.Windows.Forms.Label();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.groupBox3 = new System.Windows.Forms.GroupBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.usageThreadsInPool = new UsageControl.UsageControl();
			this.groupBox4 = new System.Windows.Forms.GroupBox();
			this.usageHistorySTP = new UsageControl.UsageHistoryControl();
			this.pcActiveThreads = new System.Diagnostics.PerformanceCounter();
			this.pcInUseThreads = new System.Diagnostics.PerformanceCounter();
			this.pcQueuedWorkItems = new System.Diagnostics.PerformanceCounter();
			this.pcCompletedWorkItems = new System.Diagnostics.PerformanceCounter();
			((System.ComponentModel.ISupportInitialize)(this.spinIdleTimeout)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.spinMaxThreads)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.spinMinThreads)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.spinInterval)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.spinConsumingTime)).BeginInit();
			this.groupBox2.SuspendLayout();
			this.groupBox3.SuspendLayout();
			this.groupBox1.SuspendLayout();
			this.groupBox4.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.pcActiveThreads)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.pcInUseThreads)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.pcQueuedWorkItems)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.pcCompletedWorkItems)).BeginInit();
			this.SuspendLayout();
			// 
			// btnStart
			// 
			this.btnStart.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.btnStart.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnStart.Location = new System.Drawing.Point(432, 352);
			this.btnStart.Name = "btnStart";
			this.btnStart.Size = new System.Drawing.Size(72, 24);
			this.btnStart.TabIndex = 0;
			this.btnStart.Text = "Start";
			this.btnStart.Click += new System.EventHandler(this.btnStart_Click);
			// 
			// btnStop
			// 
			this.btnStop.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.btnStop.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.btnStop.Location = new System.Drawing.Point(520, 352);
			this.btnStop.Name = "btnStop";
			this.btnStop.Size = new System.Drawing.Size(72, 24);
			this.btnStop.TabIndex = 1;
			this.btnStop.Text = "Stop";
			this.btnStop.Click += new System.EventHandler(this.btnStop_Click);
			// 
			// label1
			// 
			this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label1.Location = new System.Drawing.Point(104, 256);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(104, 24);
			this.label1.TabIndex = 2;
			this.label1.Text = "Minimum Threads";
			this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label3
			// 
			this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.label3.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label3.Location = new System.Drawing.Point(104, 288);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(104, 24);
			this.label3.TabIndex = 4;
			this.label3.Text = "Maximum Threads";
			this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label4
			// 
			this.label4.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.label4.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label4.Location = new System.Drawing.Point(104, 320);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(120, 24);
			this.label4.TabIndex = 5;
			this.label4.Text = "Idle timeout (Seconds)";
			this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// label2
			// 
			this.label2.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label2.Location = new System.Drawing.Point(8, 16);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(72, 24);
			this.label2.TabIndex = 3;
			this.label2.Text = "In pool (Red)";
			this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// lblThreadsInPool
			// 
			this.lblThreadsInPool.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.lblThreadsInPool.Location = new System.Drawing.Point(80, 16);
			this.lblThreadsInPool.Name = "lblThreadsInPool";
			this.lblThreadsInPool.Size = new System.Drawing.Size(80, 24);
			this.lblThreadsInPool.TabIndex = 11;
			this.lblThreadsInPool.Text = "XXXXXXXXX";
			this.lblThreadsInPool.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// label5
			// 
			this.label5.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.label5.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.label5.Location = new System.Drawing.Point(336, 258);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(280, 24);
			this.label5.TabIndex = 12;
			this.label5.Text = "Interval between work item production (milliseconds)";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
			// 
			// spinIdleTimeout
			// 
			this.spinIdleTimeout.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.spinIdleTimeout.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.spinIdleTimeout.Location = new System.Drawing.Point(8, 320);
			this.spinIdleTimeout.Minimum = new System.Decimal(new int[] {
																			1,
																			0,
																			0,
																			0});
			this.spinIdleTimeout.Name = "spinIdleTimeout";
			this.spinIdleTimeout.Size = new System.Drawing.Size(88, 29);
			this.spinIdleTimeout.TabIndex = 15;
			this.spinIdleTimeout.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.spinIdleTimeout.Value = new System.Decimal(new int[] {
																		  10,
																		  0,
																		  0,
																		  0});
			// 
			// spinMaxThreads
			// 
			this.spinMaxThreads.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.spinMaxThreads.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.spinMaxThreads.Location = new System.Drawing.Point(8, 288);
			this.spinMaxThreads.Minimum = new System.Decimal(new int[] {
																		   1,
																		   0,
																		   0,
																		   0});
			this.spinMaxThreads.Name = "spinMaxThreads";
			this.spinMaxThreads.Size = new System.Drawing.Size(88, 29);
			this.spinMaxThreads.TabIndex = 14;
			this.spinMaxThreads.TextAlign = System.Windows.Forms.HorizontalAlignment.Center;
			this.spinMaxThreads.Value = new System.Decimal(new int[] {
																		 10,
																		 0,
																		 0,
																		 0});
			this.spinMaxThreads.ValueChanged += new System.EventHandler(this.spinMaxThreads_ValueChanged);
			// 
			// spinMinThreads

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -