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