C # subprocesses and forms


When running a Thread whose method at the end opens a new form, does it not remain open?

var thread = new Thread( () => grafica(edad,años));

I did this and if you open the new form but only for a few milliseconds, just and you see, some idea of how to solve it?

Will I have to open the form from my main thread?

asked by HeZu Jared 28.06.2017 в 04:20

1 answer


Of this answer from SO.

You can try using a Invoke call.


public static Form globalForm;

void Main()
    globalForm = new Form();
    // Spawn threads here

void ThreadProc()
    myForm form = new myForm();
    globalForm.Invoke((MethodInvoker)delegate() {
        form.Text = "my text";

The Invoke call tells the form "Please, run this code on your thread instead of mine." Then you can make changes to the WinForms user interface from within the delegate.

For more information about Invoke : link

You must use a WinForms object that already exists to call Invoke . I have shown in the example how you can create a global object; Otherwise, if you have other Windows objects, you can use them.

answered by 28.06.2017 / 04:51