English 中文(简体)
哪些职能更加有效?
原标题:Which of these functions is the more effective one?

在使用透镜时,正在利用援引以避免十字路面(1)。

但是,有时还使用时标语避免十字路面(2)

(例如)

public partial class Form1 : Form
{

    private bool bCheckState = false;

    public Form1()
    {
        InitializeComponent();
    }

    //Button Click
    private void btnWork_Click(object sender, EventArgs e)
    {
        Thread m_Thread = new Thread(new ThreadStart(Work));
        m_Thread.Start();

    }

    private void Work()
    {
        bCheckState = true;            
        // not use invoke 
    }


    private void timer_Tick(object sender, EventArgs e)
    {
        if (bCheckState)
        {
            //tbxDisplay is winform s textBox control - printing data
            tbxDisplay.Text = bCheckState.ToString();
            bCheckState = false;
        }
    }
}

哪些措施更加有效? (1)和(2)


如果我们不使用援引方法或其他方法,在时间活动进行核对后将所处理的数据编成正文,这难道是一个问题吗? (我们听说,为了避免在校对校对校对校对校对校对校对校对校正,在时间范围内将数据编成目录,添加时间标语经常被使用,因为这既不有益也不有害。)

最佳回答

As Ben Voigt suggested, a BackgroundWorker is probably what you should be using here, unless you have a good reason to want to use something else.

“有效”是一种相当模糊的比较手段。 这并不完全清楚你在你们考虑的两种选择中回顾什么。

<代码>BackgroundWorkers简单易懂,避免使用时间。

Invoke的效力大于时间,因为比克邦成为事实与正在更新的案文之间出现拖延的情况较少。 这也将减少万国邮联的密集程度,因为你赢得了一定时间的投票。

<代码>Timer更为有效,因为read子必须停止使用,同时援引更新案文,但效果不大,因为它将浪费CPU时间检查,如果锅炉已经改变,并且可能在改变格式之前拖延时间。

As another alternative, BeginInvoke could be used to update the form without the use of a timer, and without the thread having to wait for the invoke to complete. However, if it raises an exception, your thread might not find out unless you also then call EndInvoke, which will also halt execution of the thread until the invoke is complete.

他们都有自己的优势和劣势,而且你实际上可以再说一遍“有效”。

问题回答

Just use a BackgroundWorker 查阅和处理<代码>ReportProgress和(或)RunWorkerCompleted活动,这些活动已经做好。





相关问题
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.

热门标签