How can I run this in the background c #

1

I am updating a DataGrid every 5 seconds, the problem is that sometimes it gets stuck and I need to execute it in the background. To avoid this, I have seen that I can do it with BackgroundWorker but I do not understand very well how the roll is going.

  bd.ejecutarConsulta("SELECT ID,Entrada,totalCajas,totalPeso,desechoCajas,desechoPeso,time from separacion WHERE ticket=0");
        DataTable dt = new DataTable();
        if (bd.myReader != null)
        {
            dt.Load(bd.myReader);
            dgvDatos.DataSource = dt;
            if (dgvDatos.RowCount > 0)
            {
                bd.cerrarConsulta();

                PrintDocument printDocument = new PrintDocument();
                printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(CreateReceipt); //add an event handler that will do the printing

                foreach (DataGridViewRow row in dgvDatos.Rows)
                {
                    ID = row.Cells[0].Value.ToString();
                    ent = row.Cells[1].Value.ToString();
                    tcajas = row.Cells[2].Value.ToString();
                    tpeso = row.Cells[3].Value.ToString();
                    dcajas = row.Cells[4].Value.ToString();
                    dpeso = row.Cells[5].Value.ToString();
                    time = row.Cells[6].Value.ToString();

                    printDocument.Print();
                    bd.ejecutarConsulta("Update separacion set ticket = 1 where ID =" + row.Cells[0].Value.ToString());
                }
                dgvDatos.DataSource = null;
            }
        }
    
asked by DoubleM 28.03.2018 в 23:55
source

0 answers