Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 in some point in time, but nothing happens? Cmd = Closing

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

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

do you have any idea why its not closing?.

what I really want it to close it.

in vb6 I use this

unload form2
like image 463
Katherina Avatar asked Jan 28 '26 07:01

Katherina


1 Answers

Most probably a threading issue. Try this:

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

If that doesn't work, use below modification:

public TimerMode f2 = new TimerMode();
public void DoActions(string Cmd)
{
  switch(Cmd){    
  case"Open":          
      f2.show()
      break;
  case"Closing":
       f2.Close();
       break;
  }
}
like image 140
Teoman Soygul Avatar answered Jan 30 '26 22:01

Teoman Soygul