MrSeanKon
10-21-2007, 01:20 PM
Here is the C# code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}
Thread t1,t2;
int x,y,result1,result2;
private void btn_Fire_Click(object sender,EventArgs e)
{
Random k=new Random();
x=k.Next(50);
y=k.Next(60);
t1=new Thread(new ThreadStart(Linear));
t2=new Thread(new ThreadStart(Power));
t1.Start();
t2.Start();
System.Threading.Thread.Sleep(0);
label1.Text=result1.ToString();
label2.Text=result2.ToString();
}
private void btn_Stop_Click(object sender,EventArgs e)
{
t1.Abort(); // The stop button terminates the running threads if the user
t2.Abort(); // press it in case of long calculation time (for example).
}
private void Linear()
{
// Assume that the procedure (and the next one) performs many complex calculations
// which are completed after a long time but not always.
result1=x+x;
}
private void Power()
{
result2=y*y;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WindowsApplication1
{
public partial class Form1:Form
{
public Form1()
{
InitializeComponent();
}
Thread t1,t2;
int x,y,result1,result2;
private void btn_Fire_Click(object sender,EventArgs e)
{
Random k=new Random();
x=k.Next(50);
y=k.Next(60);
t1=new Thread(new ThreadStart(Linear));
t2=new Thread(new ThreadStart(Power));
t1.Start();
t2.Start();
System.Threading.Thread.Sleep(0);
label1.Text=result1.ToString();
label2.Text=result2.ToString();
}
private void btn_Stop_Click(object sender,EventArgs e)
{
t1.Abort(); // The stop button terminates the running threads if the user
t2.Abort(); // press it in case of long calculation time (for example).
}
private void Linear()
{
// Assume that the procedure (and the next one) performs many complex calculations
// which are completed after a long time but not always.
result1=x+x;
}
private void Power()
{
result2=y*y;
}
}
}