Código
private void btncodigo_Click(object sender, EventArgs e) { if (backgroundWorker1.IsBusy != true) { this.pictureBox1.Visible = true; this.btncodigo.Enabled = false; backgroundWorker1.RunWorkerAsync(); } //generarNuevoCodigo(); } void generarNuevoCodigo() { DataTable dt; try { // btncodigo.Visible = false; //pictureBox1.Visible = true; dt = codigo.cargar("sp_codigo_manzana").Tables[0]; txtid.Text = nuevo.generaCodigo(dt); //aqui me da la excepcion }//try catch (Exception ex) { //throw new Exception("Error " + ex.Message); }//catch finally { // pictureBox1.Visible = false; //btncodigo.Visible = true; }//finally } private void txtdescrip_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == Convert.ToChar(Keys.Enter)) { btnguardar.Select(); btnguardar.Focus(); } } private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { generarNuevoCodigo(); } private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Cancelled == true) { this.btncodigo.Enabled = true; this.pictureBox1.Visible = false; } else if (e.Error != null) { this.btncodigo.Enabled = true; this.pictureBox1.Visible = false; } else { this.btncodigo.Enabled = true; this.pictureBox1.Visible = false; } }//void generar nuevo codigo
todos los controles los creo en tiempo de diseño y no se como manejarlos haciendo nuevos hilos durante la ejecucion