ReadXML - Threading - Static Classes - Progress Indicators

J

James Morton

I have a Static DataSet in a class file that I am using globally between a
few forms. The main form populates the dataset through a menu option which
invokes ReadXML in the class file to populate the DataSet. The ReadXML is a
rather lengthy operation with >5mb xml files (I am reading in the schema and
ignoreschema on read). This has presented several problems

1) What kind of progress bar can I show during load since I can't increment
while ReadXML is reading the xml file, do I have to override the base class
for read xml or is their a simpler way, the progress bar wouldn't have to be
exact?

2) I am thinking I need to start a seperate thread from the main form
calling the CreateDataSetFromXML in my class file. I don't know alot about
threading and right now the delegate works to call the createDataSet but
does not sync correctly to bind the datagrid on the main form. It basically
leads me to ask how can I struture serial operations within a thread. Also
how can I fire an event from a thread once a particular part (the ReadXML)
has finished, so I could, for instance, stop the progress bar.

3) I am fairly new to windows forms and am looking for a good tutorial on
how I can have a seperate form with a progress bar have the front focus and
recieve msg's from functions in other class/form files and put the
application into a "wait" state until the processing is finished so I
prevent "application not responding".

Anyways I know this is probably alot of info, and I can find alot of this on
the web but I need a really good functional overview, i.e. I feel like I
have a big puzzle , most of the pieces, but no finished picture to work
from. I'll post whatever samples from the code you would like to see.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi James


1) What kind of progress bar can I show during load since I can't increment
while ReadXML is reading the xml file, do I have to override the base class
for read xml or is their a simpler way, the progress bar wouldn't have to be
exact?

Do you really have to indicate the exact progress? Even as this would be
the best maybe with just an animated icon or image is enough for the user to
understand the app is working and not hanged. think like the windows
explorer when you are copying files.
2) I am thinking I need to start a seperate thread from the main form
calling the CreateDataSetFromXML in my class file. I don't know alot about
threading and right now the delegate works to call the createDataSet but
does not sync correctly to bind the datagrid on the main form. It basically
leads me to ask how can I struture serial operations within a thread. Also
how can I fire an event from a thread once a particular part (the ReadXML)
has finished, so I could, for instance, stop the progress bar.

You have to create a thread from where the dataset will be read from, I
assume that in your class where the dataset reside you will have a Load()
kind of method.
under this escenario I would do this:
1- Create a form like the "copying
 
J

James Morton

Sorry I think alot of your msg got cut off
Ignacio Machin ( .NET/ C# MVP ) said:
Hi James


to

Do you really have to indicate the exact progress? Even as this would be
the best maybe with just an animated icon or image is enough for the user to
understand the app is working and not hanged. think like the windows
explorer when you are copying files.


You have to create a thread from where the dataset will be read from, I
assume that in your class where the dataset reside you will have a Load()
kind of method.
under this escenario I would do this:
1- Create a form like the "copying
this
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi James

1) What kind of progress bar can I show during load since I can't increment
while ReadXML is reading the xml file, do I have to override the base class
for read xml or is their a simpler way, the progress bar wouldn't have to be
exact?

I think that having a exact progress bar is too expensive here, unless that
it's 100% needed i would suggest you using some animation aka windows
explorer's copying files.
2) I am thinking I need to start a seperate thread from the main form
calling the CreateDataSetFromXML in my class file. I don't know alot about
threading and right now the delegate works to call the createDataSet but
does not sync correctly to bind the datagrid on the main form. It basically
leads me to ask how can I struture serial operations within a thread. Also
how can I fire an event from a thread once a particular part (the ReadXML)
has finished, so I could, for instance, stop the progress bar.

a possible escenario is this, for sure you have a public static void Load()
method where your static dataset lives.
assumig that you create a new form with the animation and stuff, in the Load
method you create the new thread , this thread calls the Load method and
after that it should call a method to be executed in the main thread, you
do this by using Control.Invoke just before ends the thread. in this method
you can simply close the form.


I can send you code for this if you want

Cheers,
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi james,

sorry for that, a windows popup on my screen and I kind of confused some
keys combination and I sent the message without mean it.

Did you solve your problem?

Here is the code I'm using to do a similar thing, Please note that I removed
ALL but the 3 methods involved so the code will not compile !!!

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


public delegate void ProcessedFileHandler( );
Thread workingThread;

private System.Windows.Forms.ProgressBar progressBar1;

void Done()
{
MessageBox.Show("Done");
}

void ImportImage( )
{
foreach(string imageURL in files)
{
//Do my processing
}
//inform the UI that I'm done
this.progressBar1.Invoke( new ProcessedFileHandler( this.Done), null);
}

private void ImportImages_Load(object sender, System.EventArgs e)
{
this.workingThread = new Thread(new ThreadStart(this.ImportImage));
this.workingThread.Start();
}
 
J

James Morton

Yep that does help I have been reading up on Control.Invoke and getting a
better understanding of how delegates and threads work together. i probably
won't have 100% efficient code the first go but will post it all her so
everyone can analyze it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top