Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. best pratice

best pratice

Scheduled Pinned Locked Moved C#
databasecsharpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    the last free name
    wrote on last edited by
    #1

    Hi all, I need some advice on the best method to impelemt some functionality. I have a reader obj that reads all the files in a folder, running in a thread. After each file has been read I call a processor obj to manipulte the data and fill a database. I'd like to process one file while reading the next, but limit the processor to only one instance (to prevent duplication of data in the DB). If the reader finishes reading before the processor it should wait until the processor is done its current data load, but if the porcessor has finished then the reader should make a new processor and then continue to read the next file. So whats the best method of controling the reader depending on the state of the processor? I should point out that I'm fairly new to C# (six months) Thanks

    D 1 Reply Last reply
    0
    • T the last free name

      Hi all, I need some advice on the best method to impelemt some functionality. I have a reader obj that reads all the files in a folder, running in a thread. After each file has been read I call a processor obj to manipulte the data and fill a database. I'd like to process one file while reading the next, but limit the processor to only one instance (to prevent duplication of data in the DB). If the reader finishes reading before the processor it should wait until the processor is done its current data load, but if the porcessor has finished then the reader should make a new processor and then continue to read the next file. So whats the best method of controling the reader depending on the state of the processor? I should point out that I'm fairly new to C# (six months) Thanks

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      If your only going to be using a single instance processor, why read ahead of it? You're not gaining any real performance benefit because of the single threaded nature of your design. One thread is constantly waiting for another to complete it's work. The FileStream classes already do read/write caching on their own, so why duplicate its effort? If you could use a multiple instance processor, instead of a single, THEN you'd see the performance gain. Also, your reader object shouldn't be reading the files itself. Your design should have an engine that hunts down files, then passes the filename to a threaded instance of the processor. That way, the processor thread is doing the reading and processing of the file while your engine goes on it's merry way to launch another processor on the next file. The thread pool could be used for such a task. That way, you wouldn't have to include very much code to do thread management. I only say this because I did something similar to this a few years ago. But in my case, the database made sure I wasn't duplicating data, not my processor objects. RageInTheMachine9532 "...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome

      T 1 Reply Last reply
      0
      • D Dave Kreskowiak

        If your only going to be using a single instance processor, why read ahead of it? You're not gaining any real performance benefit because of the single threaded nature of your design. One thread is constantly waiting for another to complete it's work. The FileStream classes already do read/write caching on their own, so why duplicate its effort? If you could use a multiple instance processor, instead of a single, THEN you'd see the performance gain. Also, your reader object shouldn't be reading the files itself. Your design should have an engine that hunts down files, then passes the filename to a threaded instance of the processor. That way, the processor thread is doing the reading and processing of the file while your engine goes on it's merry way to launch another processor on the next file. The thread pool could be used for such a task. That way, you wouldn't have to include very much code to do thread management. I only say this because I did something similar to this a few years ago. But in my case, the database made sure I wasn't duplicating data, not my processor objects. RageInTheMachine9532 "...a pungent, gastly, stinky piece of cheese!" -- The Roaming Gnome

        T Offline
        T Offline
        the last free name
        wrote on last edited by
        #3

        Thanks for your comments. The majority of the time the app will be run on a single instance processor machine, but there may be a case where the volume of data is so large a multi machine could be used. I wish the database would control data duplication, but the data is so poor and badly supplied that I have to do all the checking that I can. For example the data is in XML format and one 33mb file had over 10,000 violations against the schema, but it was well formed! In the interests of simplicity I leave it as single threaded.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups