The disappearance of WindowsForm

I am developing a plugin for an application, this application "consumes" my code (classLibrary) and executes the method Init()inside its own Thread. Inside Init () I have a statement while(true)so that my plugin can run continuously.

Yesterday I started creating windowsForm to configure my plugin (using XML), and now I want to show it, but it continues to disappear. My code is as follows:

As a result of this, the form will be displayed, but it will not be re-drawn, because it starts in the same thread as while (true).

MaForm settingsForm = null;

void init(){
    While(true){
      if(settingsForm == null){
         settingsForm = new MaForm();
         settingsForm.show();
      }

    }
}

A version that shows but then disappears.

MaForm settingsForm = null;
Thread worker = null;
void init(){
    While(true){
      if(worker == null){         
         worker = new Thread(new ThreadStart(formStuff));
         worker.Start();
      }    
    }
}
void formStuff()
{
     if(settingsForm == null){
         settingsForm = new MaForm();
         settingsForm.show();
      }
}

What am I doing wrong? Is there something in Threading that I don't see? What do you guys think?

+3
3

: , , DoEvents(), Windows:

if(settingsForm == null){
   settingsForm = new MaForm();
   settingsForm.show();
}


while (settingsForm != null && settingsForm.Visible)
{
    System.Windows.Forms.Application.DoEvents();
}

EDIT: , true SettingsForm. , , .

0

, , ( ).

. , , , , , .

, , . ( ) .

STA ( ). , .

+1

# using System.Threading; . Thread, , , , Form.Show() .

Main(), ShowDialog(). , .

0

Source: https://habr.com/ru/post/1717861/


All Articles