6 Replies - 1966 Views - Last Post: 19 September 2012 - 02:46 PM Rate Topic: -----

#1 Vouksh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-September 12

Multithreading, File I/O, and efficiency question

Posted 19 September 2012 - 12:14 PM

So, I'm creating an application that stores tiered data in XML format, and the program writes to and from the xml files, and compresses them into a zip file.

Right now, it has very little real data to deal with, someone else (who is going to be using the program) is going to be putting in the actual data.

I'm worried that, as they add more and more data, the program will bog down during file I/O. I doubt the files will be more than few hundred kb at their biggest, but I'd still like to make the program as smooth for the user as possible.

Would be better to use threads to execute the saving/compressing/cleaning processes? There's no real chance that there will be multiple threads accessing the same files. I'm more worried about causing overhead, and possible freezing if a file operation errors out.

The program is ~95% done, just polishing now, and it works perfectly, with only a minor hang at the app start due to several file operations needing to be done. I'd thread the initial operations, but the program relies on the data from them.

Is This A Good Question/Topic? 0
  • +

Replies To: Multithreading, File I/O, and efficiency question

#2 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4462
  • View blog
  • Posts: 7,776
  • Joined: 08-June 10

Re: Multithreading, File I/O, and efficiency question

Posted 19 September 2012 - 12:28 PM

It's always a good idea to put long running (which Disk I/O can tend towards) tasks on something other than your UI thread. If this is a Windows Forms application, you should look into BackgroundWorker. If you're using .NET 4.0, look into Tasks. If you're using 4.5, look into using Async methods.
Was This Post Helpful? 2
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5476
  • View blog
  • Posts: 11,762
  • Joined: 02-June 10

Re: Multithreading, File I/O, and efficiency question

Posted 19 September 2012 - 12:30 PM

View PostVouksh, on 19 September 2012 - 01:14 PM, said:

So, I'm creating an application that stores tiered data in XML format, and the program writes to and from the xml files, and compresses them into a zip file.

So like Microsoft Excel.

View PostVouksh, on 19 September 2012 - 01:14 PM, said:

Would be better to use threads to execute the saving/compressing/cleaning processes?

Almost always.

View PostVouksh, on 19 September 2012 - 01:14 PM, said:

The program is ~95% done, just polishing now, and it works perfectly, with only a minor hang at the app start due to several file operations needing to be done. I'd thread the initial operations, but the program relies on the data from them.

Still no excuse for the program seeming hung to the user. If nothing else, put up a splash screen and a progress bar and do the operations on another thread. Then the program feels responsive as the user can relocate and resize it during those operations.

This post has been edited by tlhIn`toq: 19 September 2012 - 12:31 PM

Was This Post Helpful? 1
  • +
  • -

#4 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4462
  • View blog
  • Posts: 7,776
  • Joined: 08-June 10

Re: Multithreading, File I/O, and efficiency question

Posted 19 September 2012 - 12:33 PM

Quote

So like Microsoft Excel.


All the modern Office programs, now. All the ".***x" file extensions are zipped XML and manifest files.
Was This Post Helpful? 0
  • +
  • -

#5 Vouksh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-September 12

Re: Multithreading, File I/O, and efficiency question

Posted 19 September 2012 - 02:00 PM

Thanks for the replies. I'm working on implementing a splash screen now, so that there's no visible 'hang' on the program start.

I'm also going to push more of the file IO into separate threads. I just wasn't sure how 'safe' it was to do so, or if it was good practice.

And the data isn't from Office. I'm actually just serializing a couple structs I have and cross-referencing them to display them in a TreeView.
Was This Post Helpful? 0
  • +
  • -

#6 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4462
  • View blog
  • Posts: 7,776
  • Joined: 08-June 10

Re: Multithreading, File I/O, and efficiency question

Posted 19 September 2012 - 02:13 PM

Do yourself a favor and don't manually thread it using Thread objects. Use the tools MS made to make threading easier, like BackgroundWorkers or Tasks.
Was This Post Helpful? 0
  • +
  • -

#7 Vouksh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 19-September 12

Re: Multithreading, File I/O, and efficiency question

Posted 19 September 2012 - 02:46 PM

I'm reading up on the Tasks right now, looks like they should do the trick, but I'll definitely need to rework some code (and hope it doesn't break my program in half ><)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1