Why does my theme immediately stop after displaying a windows form?

I have a Windows Form application (Form1) that allows the user to open other Forms (FormGraph). To open a FormGraph application, I use a stream that opens it.
Here is the code that runs the stream:

private void ThreadCreateCurvedGraph()
{
    FormGraph myGraph = new FormGraph();
    myGraph.CreateCurvedGraph(...);
    myGraph.Show();
}

My problem is that it myGraphcloses right after it opens.
1) Does anyone know why this is happening and how to make it myGraphopen?
2) After the user has closed myGraph, how to end the stream?
Many thanks!

+5
source share
9 answers

. Application.Run() Form.ShowDialog(). , . :

  Thread t = new Thread(() => {
    Application.Run(new Form2());
    // OR:
    //new Form2().ShowDialog();
  });
  t.SetApartmentState(ApartmentState.STA);
  t.IsBackground = true;
  t.Start();

. - , Z-. - , . , IsBackground.

Windows , . , . ...

+5

, , , .

, perforamnce, ( / ).

Application.Run, .

, - .

, , ... , . : , LOT , , , - , , , , .

+1

. .

:

private void ThreadCreateCurvedGraph()
{
    FormGraph myGraph = new FormGraph();
    myGraph.CreateCurvedGraph(...);
    Application.Run(myGraph);
}

0

, ( - ). .

0

, , . , .

, , .

, Invoke , .

0

, (). ,

.

private void ThreadCreateCurvedGraph()
{
    FormGraph myGraph = new FormGraph();
    myGraph.CreateCurvedGraph(...);
    myGraph.Show();
    while (myGraph.IsOpen)
    {
         //process incoming messages <- this could be fun on a thread....
    }
}

IsOpen (, - ), , , IsOpen true .

, ... .

0

? , form.ShowDialog() .

0

, :

ThreadCreateCurvedGraph() myGraph .

( ), .

: , :

Application.Run(myGraph)

.
(. TomTom)

-1

, ?

private void ThreadCreateCurvedGraph()
{
     FormGraph myGraph = new FormGraph();
     myGraph.CreateCurvedGraph(...);
     myGraph.ShowDialog();
}

, , myGraph . myGraph, , ShowDialog, .

-1

All Articles