private void UC_Hilo_Display_JobCompleted(object sender, EventArgs e)
        {
            try
            {
                //Are we not on the UI thread
                if (InvokeRequired)
                {
                    //Change to the UI thread
                    Invoke(new UC_Hilo_Display.JobCompletedHandler(this.UC_Hilo_Display_JobCompleted), new object[] { sender, e });
                }
                else
                {
                    //Find out who we are
                    UC_Hilo_Display j = (UC_Hilo_Display)sender;
                    //Take the thread off
                    Thread.Sleep(1500);



                    if (j.ProcesoConErrores)
                    {
                        errorID++;
                        dsErrors1.Errors.AddErrorsRow(j.mensajeErroOut, errorID, j.Name);
                    }



                    pnlThreads.Controls.Remove(j);

                    //if i am the last one and the user hadn't pressed cancel then start another thread
                    if (TotalThreads > 0 && !Cancel)
                    {
                        CreateJob(Current.ToString(), j.ComprobanteAFirmar_Info, listaEmpresa, listTocken, InfoParametros, listUsuario_de_Tocken, listmail_cuentas_correo, listmail_cuentas_correo_x_empresa);
                    }

                    //Show the data
                    dataGridView1.Refresh();
                    //Increment the overall progress bar

                    if (barProgress.Maximum > 0 && barProgress.Minimum > 0)
                    {
                        barProgress.Value++;
                    }

                    if (pnlThreads.Controls.Count == 0)
                    {
                        // no hay controles quiere decir q termio todo el proceso
                        Event_Finalizo_Proceso();
                    }
                }
            }
            catch (Exception ex)
            {
                BusSisLog.Log_Error("private void UC_Hilo_Display_JobCompleted(object sender, EventArgs e) " + ex.Message.ToString(), eTipoError.ERROR, this.ToString());
            }
        }
        private void CreateJob(string name, tb_Comprobante_Info _InfoCbteAFirmar, List <tb_Empresa_Info> _listaEmpresa,
                               List <tb_Tocken_Info> _listTocken, tb_Parametro_Info _InfoParametro, List <tb_tocken_x_usuario_tocken_Info> _listUsuario_de_Tocken
                               , List <mail_Cuentas_Correo_Info> _listmail_Cuentas_Correo_Info, List <mail_Cuentas_Correo_x_Empresa_Info> _listmail_Cuentas_Correo_x_Empresa_Info)
        {
            try
            {
                //Create the thread
                UC_Hilo_Display j = new UC_Hilo_Display(name + " Firmando comprobante #:" + _InfoCbteAFirmar.IdComprobante.ToString());
                j.ComprobanteAFirmar_Info = _InfoCbteAFirmar;
                j.ListEmpresa             = _listaEmpresa;
                j.listTocken                        = _listTocken;
                j.InfoParametros                    = _InfoParametro;
                j.listUsuario_de_Tocken             = _listUsuario_de_Tocken;
                j.listmail_cuentas_correo           = _listmail_Cuentas_Correo_Info;
                j.listmail_cuentas_correo_x_empresa = _listmail_Cuentas_Correo_x_Empresa_Info;



                //Make sure it will resize to the container whatever the size
                j.Dock = DockStyle.Top;

                //Tell it how much to sleep so it will look like it is doing something
                j.MaxSleepTime = MaxSleepTime;

                //Consume the Job Completed event so that we can know when the thread is done
                j.JobCompleted += new UC_Hilo_Display.JobCompletedHandler(this.UC_Hilo_Display_JobCompleted);
                //Consume the Job Event event so that we can know when the thread has a message
                j.JobEvent += new UC_Hilo_Display.JobEventHandler(this.UC_Hilo_Display_JobEvent);

                //add the thread to the panel so it can be viewed
                pnlThreads.Controls.Add(j);

                //Start the thread
                j.Start();

                //Adjust the counters
                TotalThreads--;
                Current++;
            }
            catch (Exception ex)
            {
                BusSisLog.Log_Error("private void CreateJob(string name, " + ex.Message.ToString(), eTipoError.ERROR, this.ToString());
            }
        }