Where to do the Loading tasks for application ?

C

Cerebrus

Hi all,

I have an Windows application in which the startup form is called
"MainForm". Now when this form loads, I need to do some intensive tasks
like loading and parsing an XML file, that takes about 10-12 secs.

Initially I was doing it through Multi-threading, by calling the
intensive function (refer to as "LongTask()"), in a separate thread, in
the Load Event of the form. But the pitfall was that the user could
click the MenuItem that requires that function to have completed...

I have since added a "Loading" form with a progressbar as the startup
form, so that MainForm is shown only after all the Loading is done.

Now I am confused about where to add the task intensive function?
Should I transfer all it's code to the "Loading" form ? Or should I
make it a Public function in MainForm and call it from the "Loading"
form ? Or should I use a Shared Sub Main ?

An added complication is that I have to keep track of the progress of
the "LongTask" to show it in a progress bar.

I hope I am able to communicate the problem effectively.

Regards,

Cerebrus.
 
A

aaron.kempf

uh do it on the FORM_LOAD event lol

wish i coudl be more help

ps - wtf are you doing to ANY xml file that takes 10-12 seconds? why
don't you just find a faster way to do that
 
C

Cerebrus

Hi,

No problem, I solved the issue.

Well, how about :
1. Loading a 2 MB Xml File, that contains Books and Authors etc, into
an XPathDocument.
2. Selecting all distinct Authors, using an XPath expression.
3. Sorting this list.
4. For each author, traversing the entire Xml file, counting the no. of
books by this Author.
5. Adding this information to an ArrayList.

Can you think of a better way to do this ?

Regards,

Cerebrus.
 
G

gene kelley

Hi,


No problem, I solved the issue.


Well, how about :
1. Loading a 2 MB Xml File, that contains Books and Authors etc, into
an XPathDocument.
2. Selecting all distinct Authors, using an XPath expression.
3. Sorting this list.
4. For each author, traversing the entire Xml file, counting the no. of
books by this Author.
5. Adding this information to an ArrayList.

Can you think of a better way to do this ?

Regards,

Cerebrus.

Is the Xml File local?

I had a similar situation using a local xml file. I converted it to
an access db which is about 1/2 the xml file size. The preformance
with the db is 10 times faster than was with the xml file.

Gene
 
C

Cerebrus

Hi Gene,

Thanks for your response.

Yes, the XML file is local. I know this could be done much faster using
a database, but the requirement in this case was to do it with an XML
file.

Oh well...

I think I have optimized it as much as possible, and the whole process
is now completed in 9 seconds. This is on my 433 MHz home PC, so I
think it might be good to go !

BTW, I found that I could gain 2.5 seconds by doing my stuff in the Sub
New() of the form, rather than the Form_Load event. I don't know what
the logic behind this could be, though.

Regards,

Cerebrus.
 

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