C # closing another form problem, Close (); does not work

I have this code on form1

TimerMode f2 = new TimerMode();
f2.show();

Now I'm trying to use this code at some point in time, but nothing happens? Cmd = Close

public void DoActions(string Cmd)
{
  switch(Cmd){

  case"Open":
      TimerMode f2 = new TimerMode();
      f2.show()
      break;
  case"Closing":
       f2.Close();
       break;
}
}

Do you have an idea why it is not closed ?.

that I really want him to close it.

in vb6 I use this

unload form2
+3
source share
2 answers

Most likely a problem with threads. Try the following:

f2.Invoke((MethodInvoker)(() => f2.Close()));

If this does not work, use the modification below:

public TimerMode f2 = new TimerMode();
public void DoActions(string Cmd)
{
  switch(Cmd){    
  case"Open":          
      f2.show()
      break;
  case"Closing":
       f2.Close();
       break;
  }
}
+2
source

I just spent hours wondering why my form doesn’t close. Turns out I forgot to check everything under

Debug-> Exceptions

NullPointerException, Framework. , Cancel true false, , ( NullPointer, .)

0

All Articles