Click here to Skip to main content
15,395,065 members
Home / Discussions / C#
   

C#

 
GeneralRe: GDI Layers Pin
Heath Stewart5-Jan-04 9:57
protectorHeath Stewart5-Jan-04 9:57 
Questionstarting other apps? Pin
Peter Reiter5-Jan-04 6:54
MemberPeter Reiter5-Jan-04 6:54 
AnswerRe: starting other apps? Pin
Guillermo Rivero5-Jan-04 7:07
MemberGuillermo Rivero5-Jan-04 7:07 
AnswerRe: starting other apps? Pin
Heath Stewart5-Jan-04 7:15
protectorHeath Stewart5-Jan-04 7:15 
GeneralRe: starting other apps? Pin
Guillermo Rivero5-Jan-04 7:22
MemberGuillermo Rivero5-Jan-04 7:22 
QuestionBest code for this multithreading issue? Pin
profoundwhispers5-Jan-04 6:32
Memberprofoundwhispers5-Jan-04 6:32 
AnswerRe: Best code for this multithreading issue? Pin
HAHAHA_NEXT5-Jan-04 7:22
MemberHAHAHA_NEXT5-Jan-04 7:22 
AnswerRe: Best code for this multithreading issue? Pin
Heath Stewart5-Jan-04 7:28
protectorHeath Stewart5-Jan-04 7:28 
profoundwhispers wrote:
What happens in case of a powercut?

Confused | :confused: What do you mean a "powercut"? If you mean loss of power, the only way you can know which threads didn't finish is to use a file to persist each thread's URL that they're working on and whether or not they've finished. This is common in many caching situations.

As far as using threads, using an array list isn't really necessary because you'll have to pass an index to each thread for them to determine which one to work on. Instead, read each ID from the XML file like you're doing and use asynchronous calls to download the file, like HttpWebRequest.BeginGetResponse. You'll pass an AsyncCallback that can write to that cache file I mentioned. If you track how many IDs you read and then keep a counter for how many times the callback was executed (be sure to use locking to increment the counter to make sure, for instance using the lock keyword) you can know which ID was last (by checking the IAsyncResult.AsyncState, which you would pass into HttpWebRequest.BeginGetResponse - this is used to pass custom data from the async call to the callback for cases such as this).

You could also devise a similar situation using the ThreadPool.QueueUserWorkItem, which also uses a delegate to start in a new thread and accepts a state object (which can be a single object of any type, including an array, list, or collection of other objects). The simple Thread class doesn't now allow such state variables and there is additional benefits to using a ThreadPool over simple threads. (See the SDK documentation for details.)

I would recommend asynchronous calls, though. The functionality is provided so you might as well use it. Also keep in mind that if you devise your own system using delegates, that the C# compilers (and probably others) automatically add asynchronous versions of the Delegate.Invoke function so you can use delegates asynchronously, too.

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
Generalcustom save/open file dialog Pin
misterbear5-Jan-04 6:31
Membermisterbear5-Jan-04 6:31 
GeneralRe: custom save/open file dialog Pin
Heath Stewart5-Jan-04 7:13
protectorHeath Stewart5-Jan-04 7:13 
GeneralRe: custom save/open file dialog Pin
misterbear5-Jan-04 8:43
Membermisterbear5-Jan-04 8:43 
GeneralRe: custom save/open file dialog Pin
Heath Stewart5-Jan-04 9:52
protectorHeath Stewart5-Jan-04 9:52 
GeneralEasy Form Question Pin
Guinness4Strength5-Jan-04 6:19
MemberGuinness4Strength5-Jan-04 6:19 
GeneralRe: Easy Form Question Pin
Heath Stewart5-Jan-04 7:04
protectorHeath Stewart5-Jan-04 7:04 
GeneralRe: Easy Form Question Pin
Niels Penneman5-Jan-04 10:11
MemberNiels Penneman5-Jan-04 10:11 
GeneralRun a External EXE File Pin
hxxbin5-Jan-04 6:16
Memberhxxbin5-Jan-04 6:16 
GeneralRe: Run a External EXE File Pin
Heath Stewart5-Jan-04 7:00
protectorHeath Stewart5-Jan-04 7:00 
GeneralRe: Run a External EXE File Pin
hxxbin5-Jan-04 7:07
Memberhxxbin5-Jan-04 7:07 
GeneralRe: Run a External EXE File Pin
Heath Stewart5-Jan-04 7:37
protectorHeath Stewart5-Jan-04 7:37 
GeneralRe: Run a External EXE File Pin
hxxbin5-Jan-04 8:42
Memberhxxbin5-Jan-04 8:42 
GeneralRe: Run a External EXE File Pin
Heath Stewart5-Jan-04 9:37
protectorHeath Stewart5-Jan-04 9:37 
GeneralRe: Run a External EXE File Pin
hxxbin5-Jan-04 11:33
Memberhxxbin5-Jan-04 11:33 
GeneralCryptography Question Pin
Mazdak5-Jan-04 4:09
MemberMazdak5-Jan-04 4:09 
GeneralRe: Cryptography Question Pin
Heath Stewart5-Jan-04 5:18
protectorHeath Stewart5-Jan-04 5:18 
GeneralRe: Cryptography Question Pin
Mazdak5-Jan-04 7:46
MemberMazdak5-Jan-04 7:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.