rendered paste bodyusing System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace WindowsApplication9
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Button button6;
private System.Windows.Forms.Button button7;
private System.Windows.Forms.Button button8;
private System.Windows.Forms.Button button9;
private System.Windows.Forms.Button button10;
private System.Windows.Forms.Button button11;
private System.Windows.Forms.Button button12;
private System.Windows.Forms.Button button13;
private System.Windows.Forms.Button button14;
private System.Windows.Forms.Button button15;
private System.Windows.Forms.Button button16;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.TextBox textBox4;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <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.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.button4 = new System.Windows.Forms.Button();
this.button5 = new System.Windows.Forms.Button();
this.button6 = new System.Windows.Forms.Button();
this.button7 = new System.Windows.Forms.Button();
this.button8 = new System.Windows.Forms.Button();
this.button9 = new System.Windows.Forms.Button();
this.button10 = new System.Windows.Forms.Button();
this.button11 = new System.Windows.Forms.Button();
this.button12 = new System.Windows.Forms.Button();
this.button13 = new System.Windows.Forms.Button();
this.button14 = new System.Windows.Forms.Button();
this.button15 = new System.Windows.Forms.Button();
this.button16 = new System.Windows.Forms.Button();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox4 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(8, 8);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 23);
this.button1.TabIndex = 0;
this.button1.Text = "start t1 and t2";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.textBox1.Location = new System.Drawing.Point(88, 160);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(264, 20);
this.textBox1.TabIndex = 1;
this.textBox1.Text = "textBox1";
//
// button2
//
this.button2.Location = new System.Drawing.Point(8, 40);
this.button2.Name = "button2";
this.button2.TabIndex = 2;
this.button2.Text = "create t1";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(8, 72);
this.button3.Name = "button3";
this.button3.TabIndex = 3;
this.button3.Text = "create t2";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// button4
//
this.button4.Location = new System.Drawing.Point(248, 40);
this.button4.Name = "button4";
this.button4.TabIndex = 4;
this.button4.Text = "pause t1";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// button5
//
this.button5.Location = new System.Drawing.Point(248, 72);
this.button5.Name = "button5";
this.button5.TabIndex = 5;
this.button5.Text = "pause t2";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button6
//
this.button6.Location = new System.Drawing.Point(496, 40);
this.button6.Name = "button6";
this.button6.TabIndex = 6;
this.button6.Text = "abort t1";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// button7
//
this.button7.Location = new System.Drawing.Point(496, 72);
this.button7.Name = "button7";
this.button7.TabIndex = 7;
this.button7.Text = "abort t2";
this.button7.Click += new System.EventHandler(this.button7_Click);
//
// button8
//
this.button8.Location = new System.Drawing.Point(328, 40);
this.button8.Name = "button8";
this.button8.Size = new System.Drawing.Size(80, 23);
this.button8.TabIndex = 8;
this.button8.Text = "runT1 = false";
this.button8.Click += new System.EventHandler(this.button8_Click);
//
// button9
//
this.button9.Location = new System.Drawing.Point(328, 72);
this.button9.Name = "button9";
this.button9.Size = new System.Drawing.Size(80, 23);
this.button9.TabIndex = 9;
this.button9.Text = "runT2 = false";
this.button9.Click += new System.EventHandler(this.button9_Click);
//
// button10
//
this.button10.Location = new System.Drawing.Point(88, 40);
this.button10.Name = "button10";
this.button10.TabIndex = 10;
this.button10.Text = "runT1 = true";
this.button10.Click += new System.EventHandler(this.button10_Click);
//
// button11
//
this.button11.Location = new System.Drawing.Point(88, 72);
this.button11.Name = "button11";
this.button11.TabIndex = 11;
this.button11.Text = "runT2 = true";
this.button11.Click += new System.EventHandler(this.button11_Click);
//
// button12
//
this.button12.Location = new System.Drawing.Point(168, 40);
this.button12.Name = "button12";
this.button12.TabIndex = 12;
this.button12.Text = "start t1";
this.button12.Click += new System.EventHandler(this.button12_Click);
//
// button13
//
this.button13.Location = new System.Drawing.Point(168, 72);
this.button13.Name = "button13";
this.button13.TabIndex = 13;
this.button13.Text = "start t2";
this.button13.Click += new System.EventHandler(this.button13_Click);
//
// button14
//
this.button14.Location = new System.Drawing.Point(416, 40);
this.button14.Name = "button14";
this.button14.TabIndex = 14;
this.button14.Text = "unpause t1";
this.button14.Click += new System.EventHandler(this.button14_Click);
//
// button15
//
this.button15.Location = new System.Drawing.Point(416, 72);
this.button15.Name = "button15";
this.button15.TabIndex = 15;
this.button15.Text = "unpause t2";
this.button15.Click += new System.EventHandler(this.button15_Click);
//
// button16
//
this.button16.Location = new System.Drawing.Point(8, 104);
this.button16.Name = "button16";
this.button16.TabIndex = 16;
this.button16.Text = "button16";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(88, 184);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(120, 20);
this.textBox2.TabIndex = 17;
this.textBox2.Text = "textBox2";
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(88, 208);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(120, 20);
this.textBox3.TabIndex = 18;
this.textBox3.Text = "textBox3";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(248, 184);
this.textBox4.Name = "textBox4";
this.textBox4.TabIndex = 19;
this.textBox4.Text = "textBox4";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(672, 266);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.button16);
this.Controls.Add(this.button15);
this.Controls.Add(this.button14);
this.Controls.Add(this.button13);
this.Controls.Add(this.button12);
this.Controls.Add(this.button11);
this.Controls.Add(this.button10);
this.Controls.Add(this.button9);
this.Controls.Add(this.button8);
this.Controls.Add(this.button7);
this.Controls.Add(this.button6);
this.Controls.Add(this.button5);
this.Controls.Add(this.button4);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private long count = 0;
private bool runT1;
private bool runT2;
private Thread t1;
private Thread t2;
private DateTime start;
//private DateTime end;
private TimeSpan duration;
private void button1_Click(object sender, System.EventArgs e)
{
start = DateTime.Now;
runT1 = true;
t1 = new Thread(new ThreadStart(increment));
t1.Start();
runT2 = true;
t2 = new Thread(new ThreadStart(updateform));
t2.Start();
}
private void increment()
{
while (runT1)
{
count++;
}
}
private int sleep = 30;
private long lastspeed;
private void updateform()
{
while (runT2)
{
textBox1.Text = count.ToString();
textBox1.Update();
duration = DateTime.Now - start;
int seconds = (int)duration.TotalMilliseconds;
if (seconds == 0) seconds = 1;
long thisspeed = (count / seconds) / 1000;
textBox2.Text = thisspeed.ToString();
textBox3.Text = duration.ToString();
textBox4.Text = sleep.ToString();
lastspeed = thisspeed;
Thread.Sleep(sleep);
}
}
private string withSpace(string fromwhat)
{
string newstring = "";
string returnstring = "";
for(int i = fromwhat.Length-1; i >= 0; i--)
{
newstring += fromwhat[i];
if (i % 3 == 0) newstring += " ";
}
for(int i = newstring.Length-1; i >= 0; i--)
{
returnstring += newstring[i];
}
return newstring;
}
private void button2_Click(object sender, System.EventArgs e)
{
t1 = new Thread(new ThreadStart(increment));
}
private void button3_Click(object sender, System.EventArgs e)
{
t2 = new Thread(new ThreadStart(updateform));
}
private void button4_Click(object sender, System.EventArgs e)
{
t1.Suspend();
}
private void button5_Click(object sender, System.EventArgs e)
{
t2.Suspend();
}
private void button6_Click(object sender, System.EventArgs e)
{
t1.Abort();
}
private void button7_Click(object sender, System.EventArgs e)
{
t2.Abort();
}
private void button8_Click(object sender, System.EventArgs e)
{
runT2 = false;
}
private void button9_Click(object sender, System.EventArgs e)
{
runT2 = false;
}
private void button10_Click(object sender, System.EventArgs e)
{
runT1 = true;
}
private void button11_Click(object sender, System.EventArgs e)
{
runT2 = true;
}
private void button12_Click(object sender, System.EventArgs e)
{
t1.Start();
start = DateTime.Now;
}
private void button13_Click(object sender, System.EventArgs e)
{
t2.Start();
}
private void button14_Click(object sender, System.EventArgs e)
{
t1.Resume();
}
private void button15_Click(object sender, System.EventArgs e)
{
t2.Resume();
}
}
}