OK, it works.Tthanks.
I wonder is there better way for doing it instead of creating new thread?
System.out.println("Turning off");
Thread thread = new Thread(new CloseGui());
thread.start();
//CloseGui class
public void run() {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("closing");
Minecraft.getMinecraft().player.closeScreen();
}