namespace _11_threadingtest
{
internal class Program
{
static int[] numbers = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 , 11 , 12};
static int sum = 0;
static object lockObject = new object();
static int halfway = [Link] / 2;
static MymathLib mymathLibobj = new MymathLib();
static void Main(string[] args)
{
//Thread thread1 = new Thread((calculateSum));
//Thread thread2 = new Thread((calculateSum));
//[Link](0);
//[Link](halfway);
//[Link]();
//[Link]();
//[Link](sum);
Thread thread3 = new Thread(([Link]));
Thread thread4 = new Thread(([Link]));
[Link]();
[Link]();
[Link]();
[Link]();
static void calculateSum(object Startindex) {
[Link]("some running the other method");
[Link]($"the other method thread
{[Link]}");
[Link](1000);
int startindex = (int)Startindex;
//int endindex = (int)Endindex;
for (int i = startindex; i < (halfway + (int)Startindex); i++) {
lock (lockObject) {
[Link](1000);
[Link]($"the other method thread
{[Link]}");
[Link]("i = " + i);
sum += numbers[i];
}
}
[Link]("Finished the other method");
[Link]($"the other method thread
{[Link]}");
}
}
class MymathLib
{
public int Numb1;
public int Numb2;
Random randnumb = new Random();
static object lockObject = new object();
public MymathLib() {
[Link]("some running the other method");
[Link]($"the other method thread
{[Link]}");
}
public void Divide() {
for(int i = 0; i < 100000; i++)
{
lock (lockObject)
{ //safe thread objects.
Numb1 = [Link](1,2);
Numb2 = [Link](1,2);
//other thread rest the values of numb1 and numb2
try { int division = Numb1 / Numb2;
//[Link](1000);
//[Link]($"the other method thread
{[Link]} division value {division}");
}
catch(Exception ex) {
[Link]($"the other method thread
{[Link]} division value exception");
[Link](); }
Numb1 = 0;
Numb2 = 0;
}
}
}
}
}