The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by btakita]

Hello,

I'm using multithreading with ADO.NET.
What I am trying to do is call the Fill method from a OleDataAdapter class on
a seperate thread.

I have a form with textboxes bound to a table, two datagrids bound to their
respective tables, and a combobox bound to another table.
There is a navigator control in the form that moves data to other records.

I encapuslated the database access to data access classes, which are all
inherited from a base class.

In the base class, I have a Fill method that calls a thread that fills the
DataTable object.

Everything works when the form is loaded. However, when I go to the next
record, the application crashes. I don't see where the exception can possibly
be because the exceptions should be handled.

I also do not know how to debug this application. Do you know whats going on?

The souce code is appended to this message.

Thank you,
Brian Takita

public void Fill()
{
try
{
currentThread = new Thread(new ThreadStart(FillDataSet));
currentThread.Name = _table.TableName + " Fill";
currentThread.Priority = ThreadPriority.Normal;
currentThread.IsBackground = true;
currentThread.Start();
}
catch(Exception ex)
{
throw ex;
}
}

private void FillDataSet()
{
try
{
string commandText = da.SelectCommand.CommandText;
string where = "";

MessageBox.Show(this.ToString());

lock(da.SelectCommand)
{
if (RowFilter != "")
{
where = " Where " + RowFilter;
da.SelectCommand.CommandText += where;
}

lock(_table)
{
da.Fill(_table);
}

if (where != "")
{
da.SelectCommand.CommandText = commandText;
}
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
throw ex;
}
}
import-bot (20211) [Avatar] Offline
#2
Re: MultiThreading causes my app to crash
[Originally posted by alan]

When do you reset the select command text?

da.SelectCommand.CommandText += where;