私はこの作業をしようとしましたが、GUI で何も更新されず、コードに表示されたエラーにアプリが存在します。
ListViewItem item;
public void SetStatusStrip()
{
BackgroundWorker bw = new BackgroundWorker();
bw.WorkerReportsProgress = true;
listviewTables.Columns.Add(gDatabase);
bw.DoWork += new DoWorkEventHandler(
delegate(object o, DoWorkEventArgs args)
{
BackgroundWorker b = o as BackgroundWorker;
try
{
MySqlCommand iCommand = new MySqlCommand("SHOW TABLES;", iCon);
iRead = iCommand.ExecuteReader();
int i = 0;
while (iRead.Read())
{
item = new ListViewItem(new[] { iRead.GetString(0) });
bw.ReportProgress(i);
i++;
}
}
catch (MySqlException ex)
{
MessageBox.Show("There was an error getting tables from the database: " + gDatabase + ".\n\nError Dump:\n" + ex, "MySQL Error!");
return;
}
});
bw.ProgressChanged += new ProgressChangedEventHandler(
delegate(object o, ProgressChangedEventArgs args)
{
progressBar1.Value = args.ProgressPercentage;
listviewTables.Items.Add(item); // I get error here: System.ArgumentException
});
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(
delegate(object o, RunWorkerCompletedEventArgs args)
{
progressBar1.Value = 0;
// Finished.
});
bw.RunWorkerAsync();
}