Handle an event in a child form while the parent form is running

Suppose that I have Form1 as a parent from in a MDI Windows forms application. It has a btnStart button, which simply does a lot of calculation, let say:

double i;
while(blnContinue)
{
i=(i+1)%100000;
}

Form2 is a child with btnStop button, which simply assign blnContinue = false; so that the while loop breaks;

But the point is that, the Form2 cannot raise the event when the btnStop is pressed.

In this case, it's straightforward to make the function containing the while loop in a separate thread and create the btnStop in the parent form.

But I must do the "infinite" while loop in the main thread, so I it's not allowed to make it as a thread and start/stop it.

Anyone knows how to process the event of the Form2? Thanks in advance!

Answers


You will need to call Application.DoEvents inside the loop, say every 100ms. I don't think there is any other option. Without that your entire app will appear locked and no events will fire anywhere so no chance to do anything. Is there something stopping you using another thread?


Need Your Help

JsViews : two-way binding issue

javascript jsviews

When you bind an additional attribute in data-link, the default bindng and trigger=true stopped working. There is no error or anything obvious. But it doesn't work.

AngularJS authentication

angularjs q

Before I go to far I am hoping someone can tell me if I am handling this situation correctly or if there is a far easier way I am just missing. We have a web page made using AngularJS and Web API....

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.