Multi thread

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ruso

    Multi thread

    I am searching some string in files in the folders. But i want to
    search them with multithread form example 5 threads at the same time
    how can i do thanks
  • Ignacio Machin \( .NET/ C#  MVP \)

    #2
    Re: Multi thread

    Hi,

    You can use several ways, onbe way is to have a queue with the files to be
    processed, ( you can use a sync. queue, well you MUST ! really ) then you
    create the X threads that get the file from the queue, you will have to keep
    the results in an arraylist or something like that ( also must be sync to
    avoid problems )

    That's pretty much what you need I think , just post back if yuo need more
    help,

    Cheers,

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

    "ruso" <rustem40@yahoo .com> wrote in message
    news:5bf8bf9b.0 408020512.7d88f 159@posting.goo gle.com...[color=blue]
    > I am searching some string in files in the folders. But i want to
    > search them with multithread form example 5 threads at the same time
    > how can i do thanks[/color]


    Comment

    • Nicholas Paldino [.NET/C# MVP]

      #3
      Re: Multi thread

      ruso,

      What I would do is use the ThreadPool class. This will allow you to
      call a method which takes one parameter of type object (through the
      WaitCallback delegate). You would then call the QueueUserWorkIt em method,
      passing the directories to the method that you want to be processed. This
      would allow you to queue the requests, and let the ThreadPool allocate the
      threads accordingly.

      Hope this helps.

      --
      - Nicholas Paldino [.NET/C# MVP]
      - mvp@spam.guard. caspershouse.co m

      "ruso" <rustem40@yahoo .com> wrote in message
      news:5bf8bf9b.0 408020512.7d88f 159@posting.goo gle.com...[color=blue]
      > I am searching some string in files in the folders. But i want to
      > search them with multithread form example 5 threads at the same time
      > how can i do thanks[/color]


      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: Multi thread

        ruso <rustem40@yahoo .com> wrote:[color=blue]
        > I am searching some string in files in the folders. But i want to
        > search them with multithread form example 5 threads at the same time
        > how can i do thanks[/color]

        See http://www.pobox.com/~skeet/csharp/multithreading.html

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • William Stacey [MVP]

          #5
          Re: Multi thread

          I think you will find in the end that using multithreads (unless you have a
          multi-disks your searching and/or multi-cpus) will be slower then doing this
          serial. Why? Because you will be stoping the progress of one thread to
          start/finish progress on another. You will also be jumping the drive around
          instead of just reading a to b. However if you just want to use threads for
          learning, then others have posted info to help. If you do try it both ways,
          please post the results. Cheers!

          --
          William Stacey, MVP

          "ruso" <rustem40@yahoo .com> wrote in message
          news:5bf8bf9b.0 408020512.7d88f 159@posting.goo gle.com...[color=blue]
          > I am searching some string in files in the folders. But i want to
          > search them with multithread form example 5 threads at the same time
          > how can i do thanks[/color]

          Comment

          Working...