I am very very new to WPF. I looked in the internet for several examples and tutorials about threading. They've their own way to describe. But for naive like me, I want to understand with my own style.
And I can begin my ever first Threading using database update feature.
Here is the scenario:
I have a large amount of data to insert in the database. For now let's assume the following code (this process will initiate as soon as I hit "proceed" button:
int initial = 0;
int maxData = 10
while (initial<maxData) {
//Database query here
}
The above process will run in different thread.
Next I have a "label" in my main window. For each database query, I would like to show some message in label.
For example,
// this will happen in default UI thread.
label.Content = "Updating"; // Specifically for @TomTom ;)
EDIT: I've done the following:
var task = new Task(() =>
{
for (int i=0; i<10; i++) {
//Create new Grid HERE
// Add Table with some dynamic data here..
// print the above Grid here.
}
});
task.ContinueWith((previousTask) =>
{
label.Content = printerStatus(); // will return "Out of Paper", "printing", "Paper jam", etc.
},
TaskScheduler.FromCurrentSynchronizationContext());
label.Content = "Sending to printer";
The program will return error saying "The calling thread must be STA, because many UI components require this."
I have no idea what to do next. Please help!