I start a stream in which there is a while loop (true). In the cycle there is
while (form.trigger == "pause") { if (form.trigger_status == "start") { Action action_trigger = () => form.textBox1.Text = "ΠΠΎΡΠΎΠΊ ΠΏΡΠΈΠΎΡΡΠ°Π½ΠΎΠ²Π»Π΅Π½ \r\n" + form.textBox1.Text; form.textBox1.Invoke(action_trigger); form.trigger_status = "pause"; } Thread.Sleep(1000); } The cycle parses information. It is very important that the parsing is not repeated. In the database, I have already set everything up and marked the control points for starting and stopping parsing. But, when I close the application, of course, the database may not be recorded information, which is very important to me. Therefore, by clicking on the form properties in the form designer, I created a close_app function in the FormClosing events. I wrote the following in it:
Form1 form = Application.OpenForms["Form1"] as Form1; form.trigger = "pause"; while (form.trigger_status == "start") { Thread.Sleep(1000); } form.myThread.Abort(); form.myThread.Join(); But, for some reason in the stream does not reach
while (form.trigger == "pause") Accordingly, the triger_status does not change and the application does not close. What could be the problem?