The problem is the following: there is a windows forms application. In the namespace with the form class, there is another class that evaluates the expression, and then must transfer to the form the number of these calculations to the expression so that it displays it. In the form class, I do this: I create the th1 - th3 variables, into which I will enter the number of expression calculations. I create a thpp method with the parameters called - a marker by which we define which variable to write the number of calls, calls - the number of calls
namespace MainApplication { public partial class Form1 : Form { public int th1; public int th2; public int th3; public Form1() { InitializeComponent(); } public void thpp(uint called, int calls) { if (called == 1) th1 = calls; else if (called == 2) th2 = calls; else th3 = calls; } /* ... */ }
Further, in the class that calculates something, I start a thread that I loop:
public class SomeThread(/*параметры*/) { public Thread th; public int callCount; public SomeThread() { callCount = 0; th = new Thread(delegate() { ThreadMethod(/*параметры*/); }); if (th.IsAlive == false) th.Start(); } private void ThreadMethod(/*параметры*/) { //вычисления while (true) { //вычисления параметра called, который определяет конкретный поток callCount++; (new Form1()).thpp(called, callCount); } } }
So callCount is not passed to the form. I think because new Form1 () creates a temporary copy of the form. But I don’t know how to do it right. I am writing in VS 2010. .Net Framework 3.5, it seems.
th.IsAlive
? - VladD