using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading.Tasks;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int Fx(int
a, int b, int c=4)
{
return 100 * a + 10 * b + c;
}
private void
button1_Click(object sender, EventArgs e)
{
button1.Text = Fx(1, c: 3, b: 2).ToString();
//default and named parameters
}
String s = "";
int Display(int x)
{
int d = x;
for (int i = 0; i < 100000000; i++)
{
if
(d > 1234)
d += i;
else
d = -i;
}
return d;
}
private void
button4_Click(object sender, EventArgs e)
{
int[]
z = { 0, 0, 0, 0 };
for
(int i = 0; i < 4; i++)
z[i] += Display(i);
button4.Text =
(z[0]+z[1]+z[2]+z[3]).ToString();
}
private void
button2_Click(object sender, EventArgs e)
{
int[] z = { 0,
0, 0, 0 };
// ParallelOptions
options = new ParallelOptions { MaxDegreeOfParallelism
= 4 };
Parallel.For(0,
4, i =>
{
z[i] = Display(i);
});
button2.Text = (z[0] + z[1] + z[2]
+ z[3]).ToString();
/*
Parallel.ForEach(Stocks,
stock =>
{
StockService.CallService(stock);
});
*/
}
private void
button3_Click(object sender, EventArgs e)
{
int[] z = { 0,
0, 0, 0 };
Parallel.Invoke
(
() => z[0] = Display(1),
() => z[1] = Display(2),
() => z[2] = Display(3),
() => z[3] = Display(4)
);
button3.Text = (z[0] + z[1] + z[2]
+ z[3]).ToString();
}
string ShowMsgBox()
{
int[] z = { 0,
0, 0, 0 };
for (int i = 0; i < 4; i++)
z[i] +=
Display(i);
return
(z[0] + z[1] + z[2] + z[3]).ToString();
// MessageBox.Show("hello
task 1", "sdf");
}
private void
button5_Click(object sender, EventArgs e)
{
string
st = "";
Task task1 = Task.Factory.StartNew
(() => st=ShowMsgBox());
Task.WaitAll(task1);
button4.Text = st;
button5.Text = "Done";
}
private void
button6_Click(object sender, EventArgs e)
{
//Project Properties -> Add Reference
System.Numerics.BigInteger
X = new System.Numerics.BigInteger();
X = 1;
int I = Convert.ToInt32(textBox2.Text);
for
(int i = 2; i <= I; i++)
{
X *= i;
}
textBox1.Text = X.ToString();
}
}
}