I start new thread (worker) in userform, when this thread need something update in userform, then call Invoke method - invoke method delegate on main thread. Problem is how successfully close userform. I need first time finish worker thread, from this thread is time for time called main thread (Invoke). How in main thread wait until worker thread finish last loop.
Userform
public partial class FormMain : Form
{
private bool isntSignaledStop=true;
...
Here is a loop method that runs on the worker thread.
private void MenuLoop()
{
while (isntSignaledStop)
{
HeavyMethod();
Invoke(DelegateWriteResultsToMenu);
HeavyMethod2();
Invoke(DelegateWriteResultsToMenu2);
...
}
}
Main thread at end set isntSignaledStop=False. Now i need wait until worker thread is finished.