Click here to Skip to main content
15,896,338 members
Home / Discussions / C#
   

C#

 
GeneralRe: c# - derived classes Pin
mav.northwind21-Jul-07 10:32
mav.northwind21-Jul-07 10:32 
QuestionProblem with the browser control Pin
Raymond_P*21-Jul-07 6:52
Raymond_P*21-Jul-07 6:52 
QuestionLocalization Pin
Goje Melegnaw21-Jul-07 6:06
Goje Melegnaw21-Jul-07 6:06 
AnswerRe: Localization Pin
Paul Conrad21-Jul-07 6:26
professionalPaul Conrad21-Jul-07 6:26 
AnswerRe: Localization Pin
DavidNohejl21-Jul-07 9:53
DavidNohejl21-Jul-07 9:53 
QuestionThread, WaitSleepJoin Pin
Johan Martensson21-Jul-07 5:59
Johan Martensson21-Jul-07 5:59 
AnswerRe: Thread, WaitSleepJoin Pin
Luc Pattyn21-Jul-07 6:22
sitebuilderLuc Pattyn21-Jul-07 6:22 
GeneralRe: Thread, WaitSleepJoin Pin
Johan Martensson21-Jul-07 6:54
Johan Martensson21-Jul-07 6:54 
Thanks for the reply, yes I was vague, sorry.

What I'm doing is downloading a file, in four parts.
These parts should download at the same time.

I have one download-class that I call four times.
So I'm doing four threads that each starts a new thread in the download-class.

There is no sleeping or locking.

        private ArrayList downloads;<br />
        private void StartDownload()<br />
        {<br />
            downloads = new ArrayList(1);<br />
            dThreads = new ArrayList(1);<br />
            // Create a request to the file we are downloading<br />
            webRequest = (HttpWebRequest)WebRequest.Create(downloadUrl);<br />
            // Set the proxy to use if any<br />
            if (!dowloadProxy.Equals(string.Empty))<br />
                webRequest.Proxy = new WebProxy(dowloadProxy);<br />
            // Set default authentication for retrieving the file<br />
            webRequest.Credentials = CredentialCache.DefaultCredentials;<br />
            // Retrieve the response from the server<br />
            webResponse = (HttpWebResponse)webRequest.GetResponse();<br />
            //Ask the server for the file size and store it<br />
            int fileSize = (int)webResponse.ContentLength;<br />
<br />
            int partSize = fileSize / parts;<br />
            int lastPart = fileSize - partSize * parts;<br />
<br />
            int offset = 0;<br />
            for(int i=0; i<parts; i++)<br />
            {<br />
                dThreads.Add(new Thread(new ParameterizedThreadStart(test)));<br />
                string s = offset + ";" + (offset + partSize) + ";" + i;<br />
                ((Thread) dThreads[i]).Start(s);<br />
<br />
                offset += partSize;<br />
<br />
                if (i == parts - 2)<br />
                    partSize += lastPart;<br />
            }<br />
        }<br />
<br />
        private void test(object nums)<br />
        {<br />
            string[] split = ((string) nums).Split(';');<br />
            int start = Int32.Parse(split[0]);<br />
            int stop = Int32.Parse(split[1]);<br />
            //int i = Int32.Parse(split[2]);<br />
<br />
            downloads.Add(new Download());<br />
            i = downloads.Count - 1;<br />
<br />
            ((Download)downloads[i]).StartPoint = start;<br />
            ((Download)downloads[i]).EndPoint = stop;<br />
<br />
            ((Download)downloads[i]).InitDownloadFile(downloadUrl);<br />
            ((Download)downloads[i]).DownloadFile(outFile + "." + i);<br />
        }<br />

GeneralRe: Thread, WaitSleepJoin Pin
Luc Pattyn21-Jul-07 7:13
sitebuilderLuc Pattyn21-Jul-07 7:13 
GeneralRe: Thread, WaitSleepJoin Pin
Luc Pattyn21-Jul-07 7:28
sitebuilderLuc Pattyn21-Jul-07 7:28 
GeneralRe: Thread, WaitSleepJoin Pin
Johan Martensson21-Jul-07 7:49
Johan Martensson21-Jul-07 7:49 
GeneralRe: Thread, WaitSleepJoin Pin
Luc Pattyn21-Jul-07 8:18
sitebuilderLuc Pattyn21-Jul-07 8:18 
GeneralRe: Thread, WaitSleepJoin Pin
Johan Martensson21-Jul-07 9:18
Johan Martensson21-Jul-07 9:18 
GeneralRe: Thread, WaitSleepJoin Pin
Luc Pattyn21-Jul-07 9:54
sitebuilderLuc Pattyn21-Jul-07 9:54 
GeneralRe: Thread, WaitSleepJoin Pin
Johan Martensson21-Jul-07 10:39
Johan Martensson21-Jul-07 10:39 
GeneralRe: Thread, WaitSleepJoin Pin
Luc Pattyn21-Jul-07 11:03
sitebuilderLuc Pattyn21-Jul-07 11:03 
GeneralRe: Thread, WaitSleepJoin Pin
Johan Martensson21-Jul-07 11:32
Johan Martensson21-Jul-07 11:32 
GeneralRe: Thread, WaitSleepJoin Pin
Luc Pattyn21-Jul-07 11:51
sitebuilderLuc Pattyn21-Jul-07 11:51 
GeneralRe: Thread, WaitSleepJoin Pin
Luc Pattyn21-Jul-07 13:08
sitebuilderLuc Pattyn21-Jul-07 13:08 
GeneralRe: Thread, WaitSleepJoin Pin
Johan Martensson21-Jul-07 22:14
Johan Martensson21-Jul-07 22:14 
GeneralRe: Thread, WaitSleepJoin Pin
Luc Pattyn22-Jul-07 0:34
sitebuilderLuc Pattyn22-Jul-07 0:34 
GeneralRe: Thread, WaitSleepJoin Pin
Johan Martensson24-Jul-07 0:15
Johan Martensson24-Jul-07 0:15 
GeneralRe: Thread, WaitSleepJoin Pin
Luc Pattyn24-Jul-07 1:01
sitebuilderLuc Pattyn24-Jul-07 1:01 
GeneralRe: Thread, WaitSleepJoin Pin
Johan Martensson24-Jul-07 8:21
Johan Martensson24-Jul-07 8:21 
GeneralRe: Thread, WaitSleepJoin Pin
Luc Pattyn24-Jul-07 11:54
sitebuilderLuc Pattyn24-Jul-07 11:54 

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.