在 c# 中使用 WinForm App 进行操作的时间延迟

Jas*_*per 3 c# timedelay delay winforms

我在 C# 中的 Windows 窗体应用程序有问题 在这个应用程序中有一个选项卡式浏览器。现在我想在一个循环中(我做一些操作来计算下一个 url)我可以在 AddTab 之间添加一个延迟。

IE

 foreach(Urls url in Links){

        // Do something with url
         if(url.Host == "google"){ //if host is google until start the 
                                   // next AddTab i would wait 5 SEC
             addTab(url);
           //Here i Tried to use Sleep Thread , While(TimeCur-TimePre) {} but i always 
           // get Freezing and the other Tabs dont continue the loading
             Wait 5 Seconds in somehow
         }
}
Run Code Online (Sandbox Code Playgroud)

正如我所写,我不想使用线程睡眠,因为它会冻结我的表单应用程序。我已经在 TimeCur-TimeSaved+(x Second) 中使用了时间技巧,但这也会冻结表单。

我看到很多人说要使用计时器的主题,所以我尝试使用它们(没有任何结果,也许我错了)

我可以在这个循环中添加什么来延迟 AddTab 之间的打开而不冻结任何东西?

Rus*_*ell 6

使用 Windows 窗体计时器(来自工具箱)。在属性中,设置间隔设置。然后在表单设计器上双击它。这将创建一个事件处理程序,当间隔时间过去时,它将被触发(在单独的线程中)。您可以在此处完成工作,表单将保持活动状态。