E
Elliot Rodriguez
Hi:
I am writing a WinForm app that contains a DataGrid control and a StatusBar
control. My goal is to update the status bar using events from a separate
class, as well as some other simple things.
The method I am writing queries a large dataset. As part of my feedback to
the user, I am updating the status bar when the connection is made and the
dataset is actually retrieved. The dataset retrieval method I have placed on
a separate thread so that the status bar updates can be viewed by the user.
Everything works except for the actual binding of my dataset to the grid
control. when I attempt to bind my dataset, i get an error along the lines
of "cannot make control on parent thread of another control" or something to
that effect (I'm sorry, I dont have the actual text handy, and the query
takes a while so forgive the paraphrasing.). I am new to writing.NET
threading code, and would prefer to learn in this instance how it works and
how I broke it rather than copy and paste code, so can anyone please take a
sec and view below and tell me what I am missing? Some of the code I took
from the MSDN's Threading tutorial.
private void mnuGetDocuments_Click(object sender, System.EventArgs e)
{
if (MessageBox.Show(this, "Retrieve list of documents waiting for
printing?", "Confirm Queue Retrieval",
MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK)
{
// my events, QueueDocs is object outside of function scope.
QueueDocs.ConnectionEstablished += new
ConnectionMadeHandler(UpdateStatusOnConnection);
QueueDocs.DatasetReceived += new
DatasetReceivedHandler(UpdateStatusOnDataset);
this.sbOperationStatus.Text = "Retrieving queues... 0% complete";
// instance our new thread
Thread objThread = new Thread(new ThreadStart(this.GetDocuments));
objThread.Start();
while (!objThread.IsAlive)
{
Thread.Sleep(1);
objThread.Abort();
objThread.Join();
}
}
}
private void GetDocuments()
{
DataSet dsLocal = QueueDocs.RetrievePrintQueues();
// breaks here, on binding.
this.dgQueueDocuments.DataSource = dsLocal.Tables[0].DefaultView;
}
Thank you,
Elliot Rodriguez
I am writing a WinForm app that contains a DataGrid control and a StatusBar
control. My goal is to update the status bar using events from a separate
class, as well as some other simple things.
The method I am writing queries a large dataset. As part of my feedback to
the user, I am updating the status bar when the connection is made and the
dataset is actually retrieved. The dataset retrieval method I have placed on
a separate thread so that the status bar updates can be viewed by the user.
Everything works except for the actual binding of my dataset to the grid
control. when I attempt to bind my dataset, i get an error along the lines
of "cannot make control on parent thread of another control" or something to
that effect (I'm sorry, I dont have the actual text handy, and the query
takes a while so forgive the paraphrasing.). I am new to writing.NET
threading code, and would prefer to learn in this instance how it works and
how I broke it rather than copy and paste code, so can anyone please take a
sec and view below and tell me what I am missing? Some of the code I took
from the MSDN's Threading tutorial.
private void mnuGetDocuments_Click(object sender, System.EventArgs e)
{
if (MessageBox.Show(this, "Retrieve list of documents waiting for
printing?", "Confirm Queue Retrieval",
MessageBoxButtons.OKCancel,MessageBoxIcon.Question) == DialogResult.OK)
{
// my events, QueueDocs is object outside of function scope.
QueueDocs.ConnectionEstablished += new
ConnectionMadeHandler(UpdateStatusOnConnection);
QueueDocs.DatasetReceived += new
DatasetReceivedHandler(UpdateStatusOnDataset);
this.sbOperationStatus.Text = "Retrieving queues... 0% complete";
// instance our new thread
Thread objThread = new Thread(new ThreadStart(this.GetDocuments));
objThread.Start();
while (!objThread.IsAlive)
{
Thread.Sleep(1);
objThread.Abort();
objThread.Join();
}
}
}
private void GetDocuments()
{
DataSet dsLocal = QueueDocs.RetrievePrintQueues();
// breaks here, on binding.
this.dgQueueDocuments.DataSource = dsLocal.Tables[0].DefaultView;
}
Thank you,
Elliot Rodriguez