C# Asynchronous call without EndInvoke?

前端 未结 4 1290
野趣味
野趣味 2020-12-10 05:38

Take the following classes as an example.

public class A
{
   // ...
   void Foo(S myStruct){...}
}

public class B
{
   public A test;
   // ...
   void Bar         


        
4条回答
  •  Happy的楠姐
    2020-12-10 06:07

    This is an option:

    ThreadPool.QueueUserWorkItem(bcl =>
    {
        var bcList = (List)bcl;
        IAsyncResult iftAR = this.dataGridView1.BeginInvoke((MethodInvoker)delegate
        {
            int x = this.dataGridView1.Rows[0].Cells.Count - 1;
            for (int i = 0; i < this.dataGridView1.Rows.Count - 1; i++)
            {
                try
                {
                    string imgPath = bcList[i].GifPath;
                    Image bmpImage = Image.FromFile(imgPath);
                    this.dataGridView1.Rows[i].Cells[x].Value =bmpImage;
                }
                catch (Exception)
                {
                    continue;
                }
            }
        }); 
        while (!iftAR.IsCompleted) { /* wait this*/  }
    }, barcodeList);
    

提交回复
热议问题