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

C#

 
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 
well, here is the new log:


<br />
17:13.796 [000A] Start DownloadFile-Thread<br />
17:13.796 [000A] Start DownloadFile-Thread<br />
17:13.796 [000C] Do the webrequest<br />
17:13.796 [000A] Start DownloadFile-Thread<br />
17:13.796 [000D] Do the webrequest<br />
17:13.796 [000D] End the webrequest<br />
17:13.828 [000D] Retrieve the response from the server<br />
17:13.828 [000A] Start DownloadFile-Thread<br />
17:13.796 [000C] End the webrequest<br />
17:13.843 [000C] Retrieve the response from the server<br />
17:13.828 [000E] Do the webrequest<br />
17:13.843 [000F] Do the webrequest<br />
17:13.859 [000E] End the webrequest<br />
17:13.859 [000E] Retrieve the response from the server<br />
17:13.859 [000F] End the webrequest<br />
17:13.859 [000F] Retrieve the response from the server<br />
17:14.203 [000D] After Retrieve the response from the server<br />
17:14.203 [000D] Get the response-stream<br />
17:14.203 [000D] After Get the response-stream<br />
17:14.218 [000D] Start while-loop<br />
17:18.687 [000D] End while-loop<br />
The thread 0x9c4 has exited with code 0 (0x0).<br />
17:18.859 [000C] After Retrieve the response from the server<br />
17:18.859 [000C] Get the response-stream<br />
17:18.859 [000C] After Get the response-stream<br />
17:18.875 [000C] Start while-loop<br />
17:22.109 [000C] End while-loop<br />
17:22.109 [000F] After Retrieve the response from the server<br />
The thread 0x9c0 has exited with code 0 (0x0).<br />
17:22.125 [000F] Get the response-stream<br />
17:22.125 [000F] After Get the response-stream<br />
17:22.125 [000F] Start while-loop<br />
17:25.265 [000F] End while-loop<br />
The thread 0xf04 has exited with code 0 (0x0).<br />
The program '[4024] DownloadManager.vshost.exe: Managed' has exited with code 0 (0x0).<br />


and StartDownload:

<br />
private void StartDownload()<br />
        {<br />
            try<br />
            {<br />
                // Create a request to the file we are downloading<br />
                webRequest = (HttpWebRequest)WebRequest.Create(dowloadUrl);<br />
                // Set the proxy to use if any<br />
                if (!dowloadProxy.Equals(string.Empty))<br />
                    webRequest.Proxy = new WebProxy(dowloadProxy);<br />
                // Set the startingpoint of the stream if any and resume is aloud<br />
                //if (startPoint > 0 && resumeIsAloud)<br />
                //    webRequest.AddRange(startPoint);<br />
<br />
                log("Do the webrequest");<br />
                if(endOffset>0)<br />
                 webRequest.AddRange(startOffset, endOffset);<br />
                else<br />
                 webRequest.AddRange(startOffset);<br />
                log("End the webrequest");<br />
<br />
                // Set default authentication for retrieving the file<br />
                webRequest.Credentials = CredentialCache.DefaultCredentials;<br />
                log("Retrieve the response from the server");<br />
                // Retrieve the response from the server<br />
                webResponse = (HttpWebResponse)webRequest.GetResponse();<br />
                log("After Retrieve the response from the server");<br />
                //Ask the server for the file size and store it<br />
                fileSize = webResponse.ContentLength;<br />
                log("Get the response-stream");<br />
                // Get the response-stream<br />
                strResponse = webResponse.GetResponseStream();<br />
                log("After Get the response-stream");<br />
<br />
                // Set the output-stream<br />
                strLocal = new FileStream(outFile, FileMode.Create, FileAccess.Write, FileShare.Write);<br />
<br />
                // It will store the current number of bytes we retrieved from the server<br />
                int bytesSize;<br />
                // A buffer for storing and writing the data retrieved from the server<br />
                byte[] downBuffer = new byte[2048];<br />
<br />
                // Set the start-time<br />
                downStart = DateTime.Now;<br />
<br />
                log("Start while-loop");<br />
                // Loop through the buffer until the buffer is empty<br />
                while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)<br />
                {<br />
                    // Write the data from the buffer to the local hard drive<br />
                    strLocal.Write(downBuffer, 0, bytesSize);<br />
                    //CalculateDownloadingInfo();<br />
                }<br />
                log("End while-loop");<br />
            }<br />
            catch (Exception e)<br />
            {<br />
                lastError = e;<br />
                RaiseDownloadError(e);<br />
            }<br />
            finally<br />
            {<br />
                if (strResponse != null) strResponse.Close();<br />
                if (strLocal != null) strLocal.Close();<br />
            }<br />
        }               <br />


That didn't seem to make that much of a difference and the threads still runs one after the other.

You can have a look at the whole thing here: http://johanmartensson.se/downloadmanager.rar

It's quite messy, but you'll get the idea Smile | :)
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 
QuestionDataSource binding problem Pin
~~~Johnny~~~21-Jul-07 3:27
~~~Johnny~~~21-Jul-07 3:27 
AnswerRe: DataSource binding problem Pin
~~~Johnny~~~21-Jul-07 5:01
~~~Johnny~~~21-Jul-07 5:01 
GeneralRe: DataSource binding problem Pin
Urs Enzler22-Jul-07 6:24
Urs Enzler22-Jul-07 6:24 
GeneralRe: DataSource binding problem Pin
~~~Johnny~~~23-Jul-07 6:03
~~~Johnny~~~23-Jul-07 6:03 
GeneralRe: DataSource binding problem Pin
Urs Enzler29-Jul-07 21:40
Urs Enzler29-Jul-07 21:40 
Questionadd header and footer to a dynamically generated word Pin
Nitin Varambally21-Jul-07 3:23
Nitin Varambally21-Jul-07 3:23 
QuestionConverting a Form to a Windows Service Pin
Ben297521-Jul-07 2:35
Ben297521-Jul-07 2:35 
AnswerRe: Converting a Form to a Windows Service Pin
Luc Pattyn21-Jul-07 3:09
sitebuilderLuc Pattyn21-Jul-07 3:09 
QuestionAny one know how to insert new rows into DataGrid [modified] Pin
michaelqog21-Jul-07 1:51
michaelqog21-Jul-07 1:51 

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.