Threading - UI locking upXML training - does anyone have any favorite (RECENT) books?

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
So here I am trying to make my application show more details as they happen to the user. But now I have on my hands areas where the program goes unresponsive during database verification/importing.
The scenario:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; bool IsImporting = <span style="color:Blue; false;

<span style="color:Blue; private <span style="color:Blue; void ImportFiles(<span style="color:Blue; object file)
{
<span style="color:Green; // Heavy db loading/verification. Sometimes takes 10+ seconds
<span style="color:Green; // Update textbox as results come in
IsImporting = <span style="color:Blue; false;
}

<span style="color:Blue; private <span style="color:Blue; void MainProcess()
{
<span style="color:Green; // Copy files
<span style="color:Green; // Extract zipped files
ImportFiles(fileObject);
}
[/code]

<br/>
This of course was causing the UI to lock up during the ImportFiles method. Which on faster imports there was no issue with. Longer the imports became the longer the program would become unresponsive and look like it froze.
I have tried the following:

<div style="color:Black;background-color:White; <pre>
<span style="color:Blue; public <span style="color:Blue; bool IsImporting = <span style="color:Blue; false;

<span style="color:Blue; private <span style="color:Blue; void ImportFiles(<span style="color:Blue; object file)
{
<span style="color:Green; // Heavy db loading/verification. Sometimes takes 10+ seconds
<span style="color:Blue; this.BeginInvoke(<span style="color:Blue; new ThreadStart(() => {
<span style="color:Green; // Update textbox as results come in
}));
IsImporting = <span style="color:Blue; false;
}

<span style="color:Blue; private <span style="color:Blue; void MainProcess()
{
<span style="color:Green; // Copy files
<span style="color:Green; // Extract zipped files
IsImporting = <span style="color:Blue; true;
<span style="color:Blue; this.BeginInvoke (<span style="color:Blue; new ThreadStart (() => { ImportFiles(fileObject); <span style="color:Green; // Put all the heavy data transfer on a different thread.
}));
<span style="color:Blue; while (IsImporting) { } <span style="color:Green; // Loop until the import is done
}
[/code]

<br/>
Im not sure why things are still locking up or how to allow my program to stop processing the store until the importfiles method has completed without putting it into a loop and checking a completion flag... Which seems to lock up the program anyways.
How can I allow this heavy processing method to run and still update the ui as it goes, without actually freezing the ui?
I have looked up numerous threading tutorials and I just cant get them to work properly or Im horribly misunderstanding how to thread.<br/>



It appears that I need to suddenly and drastically upgrade my knowledge of XML, as well as XML-related Dot Net 4.0 programming techniques.
Would anyone care to recommend any favorite recently published books that have a heavy focus on both subjects?
(Either VB or C# will do, although I am more accustomed to VB.)

View the full article
 
Back
Top