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. Is there a way to develop FOREACH loop results with Threading?

Is there a way to develop FOREACH loop results with Threading?

Scheduled Pinned Locked Moved C#
question
3 Posts 3 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.
  • P Offline
    P Offline
    pubududilena
    wrote on last edited by
    #1

    HI All, I have written a FOREACH loop to get results .Here it is. foreach(NFConsolG lobjcongds in lobjCons.GList) { if(lobjcongds.Status==1) { try { lobjcongds.ConName=lobjCon1.TradingName; units=this.GetPublish1(sc,lobjcongds); if(units!=null && units.Length>0 && units[0]!=null && units[0].GetType().Equals(typeof(Unit))) { UnitArrayList.AddRange(units); } } catch{} } } I need to call this.GetPublish1() method using Threads.But it is inside a loop. Is there a way to use Threads for this FOREACH loop? Please advice me.

    C V 2 Replies Last reply
    0
    • P pubududilena

      HI All, I have written a FOREACH loop to get results .Here it is. foreach(NFConsolG lobjcongds in lobjCons.GList) { if(lobjcongds.Status==1) { try { lobjcongds.ConName=lobjCon1.TradingName; units=this.GetPublish1(sc,lobjcongds); if(units!=null && units.Length>0 && units[0]!=null && units[0].GetType().Equals(typeof(Unit))) { UnitArrayList.AddRange(units); } } catch{} } } I need to call this.GetPublish1() method using Threads.But it is inside a loop. Is there a way to use Threads for this FOREACH loop? Please advice me.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You can start a thread for each object, if you want to access the threads later from the main thread, just store them in a list.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      1 Reply Last reply
      0
      • P pubududilena

        HI All, I have written a FOREACH loop to get results .Here it is. foreach(NFConsolG lobjcongds in lobjCons.GList) { if(lobjcongds.Status==1) { try { lobjcongds.ConName=lobjCon1.TradingName; units=this.GetPublish1(sc,lobjcongds); if(units!=null && units.Length>0 && units[0]!=null && units[0].GetType().Equals(typeof(Unit))) { UnitArrayList.AddRange(units); } } catch{} } } I need to call this.GetPublish1() method using Threads.But it is inside a loop. Is there a way to use Threads for this FOREACH loop? Please advice me.

        V Offline
        V Offline
        Vikram A Punathambekar
        wrote on last edited by
        #3

        A couple of observations: 1. If you return a value from a method you call in a different thread, your calling method might be long gone by the time your called method completes execution. You will have to rethink your design. 2. If there are many items in your collection, you might end up spawning a huge number of threads. This is not a very good idea.

        Cheers, Vikram.


        "The weak can never forgive. Forgiveness is the attribute of the strong." - Mahatma Gandhi.

        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