I have started a little app for fun and it needs to make "form1" (See code) keep opening a new window forever. It does this, however it only does the loop after the previous window is closed. So basically it needs to keep opening up additional windows forever at the same time without the user needing to close the window that is already open. Picture of current code
Code of the whole file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace PeppaPig
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
loop:
Application.Run(new Form1());
goto loop;
}
}
}
Thanks! Any help is appreciated!
Your code waits until...
Application.Run(new Form1());
... has finished. To achieve the behaviour you want, you should create an instance of Form1 and call Show() of it.
To achieve an infinit loop there are different ways. Some examples are
while(true)
{
//do something
}
or
for(;;)
{
// do something
}
or like you already did
:loop
// do something
goto loop;
So here is an example how to get the behaviour you want:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
while (true)
{
var newForm = new Form1();
newForm.Show();
}
}