简体   繁体   中英

Function Call using Background Worker

I am having a single function InitializeList(). Now, this function I am calling from three Background worker's DoWork Event. So, does the calling of a single function from multiple Backgroundworker run parallel? 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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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