1
I have an object Combobox and I am creating a Backgroundworker to add these objects to my database. Without using the Backgroundworker I can catch the selected object but when I use the Backgroundworker returns an exception and the object is empty.
How to solve this ?
I’m trying like this.
Method that the Backgroundworker performs
/** insere Perfil + Modulo */
private void insertPerfilModulo() {
Perfil perfil = (Perfil)cbxPerfilModulo.SelectedItem;
IList<Modulo> lista = getListaModulo();
foreach(Modulo m in lista){
Permissao permissao = new Permissao();
permissao.perfil = perfil;
permissao.modulo = m;
Boolean exist = dao.isExistPerfilAndModulo(permissao);
if (exist) {
Permissao p = dao.getPermissao(permissao);
dao.update(p);
}else {
dao.insert(permissao);
}
}
}
Dowork
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) {
progressBar1.Visible = true;
insertPerfilModulo();
}
Boot that runs
private void btnSalvarPM_Click(object sender, EventArgs e) {
backgroundWorker1.RunWorkerAsync();
}
Exception
The thread '<No Name>' (0x1870) has exited with code 0 (0x0).
'PubControl.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.
A first chance exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll
The program '[5396] PubControl.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[5396] PubControl.vshost.exe: Managed (v4.0.30319)' has exited with code -1 (0xffffffff).
Has attempted to specify the members in which the
backgroundWolker1
will you access? For example, putnomeDaClasse.progressBar1.Visible = true;
– CypherPotato