简体   繁体   English

使用后台工作者的函数调用

[英]Function Call using Background Worker

I am having a single function InitializeList().我有一个函数 InitializeList()。 Now, this function I am calling from three Background worker's DoWork Event.现在,我从三个后台工作人员的 DoWork 事件调用这个函数。 So, does the calling of a single function from multiple Backgroundworker run parallel?那么,来自多个 Backgroundworker 的单个函数的调用是否并行运行? Or I have to create three different functions & pass them in different Background workers to run in parallel?或者我必须创建三个不同的函数并将它们传递给不同的后台工作人员以并行运行?

For additional information, this single function does use an update of different controls on the windows form.有关其他信息,此单个函数确实使用了 Windows 窗体上不同控件的更新。

private void InitializeList()
    {
        try
        {
            _testMaster1 = new TestMasters();
            string query = string.Empty;
            query = "SELECT TestMasterFVT01.* FROM TestMasterFVT01 WHERE ((TestMasterFVT01.ThreadNO)<>0) ORDER BY TestMasterFVT01.TestID, TestMasterFVT01.SubTestID;";

            _testMaster1 = Singleton.Instance.GetData(query);
            mainListView1.Items.Clear();
            mainListView1.Items.AddRange(Singleton.Instance.ListViewItemCollection.ToArray());

            _itemCount1 = _testMaster1.Count;

            if (_itemCount1 == 0)
            {
                MessageBox.Show("Please check Model Setting");
                Environment.Exit(0);
            }
            progressBar1.Value = 0;
            textBoxBoardName1.Select();
        }
        catch (Exception ex)
        {
            MessageBox.Show("Please check Model Setting");
            Environment.Exit(0);
            Logger.Error(ex);
        }
    }


void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
    {
InitializeList();
}

void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
InitializeList();
}

void backgroundWorker3_DoWork(object sender, DoWorkEventArgs e)
        {
InitializeList();
}

Calling of a single function from multiple Backgroundworker run parallel.从多个 Backgroundworker 调用单个函数并行运行。 And if this single function does use an update of different controls on the windows form, you can call the function from three Background workers如果这个单一的函数确实使用了 windows 窗体上不同控件的更新,则可以从三个后台工作者调用该函数

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM