English 中文(简体)
c#[复制]使用WinForm App的延迟时间
原标题:Time Delay for operations using WinForm App in c# [duplicate]

I have a problem with a Windows Form Application in C# Inside This application there is a Tabbed Browser. Now i want that in a loop (where i do some operation to calculate the next url) i could add a delay between AddTab.

页: 1

 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
         }
}

正如我写的“一心一意想要使用睡觉”,它冻结了我的表格应用。 我已经利用了与时日Saved+(x Second)的时间交接,但这也冻结了形式。

我看到许多人说是使用Timers,因此,我试图使用这些话题(没有结果,可能是错误的东西)。

在此 lo中,我可以补充的是,在不冻结任何东西的情况下,推迟在AddTab之间开放?

最佳回答
    var thread = new System.Threading.Thread(p =>
    {
        lock (YourTabControl)
        {
            Action action = () =>
            {
                addTab(url);
            };
            this.Invoke(action);
            if(url.Host == "google")
                System.Threading.Thread.Sleep(5000);
        }
    });
    thread.Start();
问题回答

使用Windows表格时间(工具箱)。 在财产方面,确定间隔期。 然后,在表格设计商上两次点击。 这将产生一个事件手,在间隔时间长时(单独地)发射。 你可以在这里开展工作,形式将保持积极。





相关问题
Bring window to foreground after Mutex fails

I was wondering if someone can tell me what would be the best way to bring my application to the foreground if a mutex was not able to be created for a new instance. E.g.: Application X is running ...

How to start WinForm app minimized to tray?

I ve successfully created an app that minimizes to the tray using a NotifyIcon. When the form is manually closed it is successfully hidden from the desktop, taskbar, and alt-tab. The problem occurs ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

Handle DataTable.DataRow cell change event

I have a DataTable that has several DataColumns and DataRow. Now i would like to handle an event when cell of this DataRow is changed. How to do this in c#?

Apparent Memory Leak in DataGridView

How do you force a DataGridView to release its reference to a bound DataSet? We have a rather large dataset being displayed in a DataGridView and noticed that resources were not being freed after the ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

WPF-XAML window in Winforms Application

I have a Winforms application coded in VS C# 2008 and want to insert a WPF window into the window pane of Winforms application. Could you explain me how this is done.

热门标签