Hi
I am using a Backgroundworker do load media files from a Sql Server. The user should be able to cancel this operation, but I am not sure how to implement this. If I call backgroundWorker1.CancelAsync(); there is no while-loop I can stop.
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
...
XmlReader
myReader = XmlReader.Create(sqlCommand.ExecuteXmlReader(), mySettings);....
}
Thank you

Backgroundworker + Sql
rodniko
Thanks for the answer, but what I want to know is, how can I cancel Sql queries If the the transfer rate is low or the Sql Server unreachable, how can I stop the BackgroundWorker (a user can hit cancel to abort the operation)
public DataTable GetData(string sqlCmd)
{
sqlCommand = new SqlCommand(sqlCmd, sqlConnection);
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.SelectCommand = sqlCommand;
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
adapter.Fill(table); // I want to allow users to cancel this statement which is run by BackgroundWorker
sqlCommand = null;
return table;
}
P.S How can I format code examples for the forum
Thanks again.
Bram Veenhof
Hi,
This may help: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=754662&SiteID=1