【发布时间】:2018-11-21 08:48:05
【问题描述】:
为了好玩,我启动了一个小应用程序,它需要让“form1”(参见代码)永远打开一个新窗口。它执行此操作,但是它仅在前一个窗口关闭后执行循环。所以基本上它需要永远打开额外的窗口,而用户不需要关闭已经打开的窗口。 Picture of current code
整个文件的代码:
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;
}
}
}
谢谢!任何帮助表示赞赏!
【问题讨论】:
-
欢迎来到 stackoverflow.com。请花一些时间阅读the help pages,尤其是名为"What topics can I ask about here?" 和"What types of questions should I avoid asking?" 的部分。也请take the tour 和read about how to ask good questions。最后请阅读this question checklist。
-
不要发布代码图片,而是复制粘贴代码本身。
-
在与代码相关的注释中,不要使用标签和
gotofor 循环。事实上,你真的不应该使用goto根本。 -
while (true)通常是一种常用的方式。此外,用户通常不太喜欢拥有一个无法退出的程序。
标签: c# loops infinite-loop