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

C#

 
GeneralRe: Thread, WaitSleepJoin Pin
Johan Martensson21-Jul-07 6:54
Johan Martensson21-Jul-07 6:54 
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 
Ok, I have removed the threads and use only the threads in Download-class.

From the log I got:

<br />
'DownloadManager.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br />
'DownloadManager.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br />
'DownloadManager.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Windows.Forms\2.0.0.0__b77a5c561934e089\System.Windows.Forms.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br />
'DownloadManager.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br />
'DownloadManager.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br />
'DownloadManager.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br />
'DownloadManager.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\Johan\Desktop\DownloadManager\DownloadManager\bin\Debug\DownloadManager.vshost.exe', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br />
'DownloadManager.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_32\System.Data\2.0.0.0__b77a5c561934e089\System.Data.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br />
'DownloadManager.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Deployment\2.0.0.0__b03f5f7f11d50a3a\System.Deployment.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br />
'DownloadManager.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br />
The thread 0x13b8 has exited with code 0 (0x0).<br />
The thread 0x1a0 has exited with code 0 (0x0).<br />
'DownloadManager.vshost.exe' (Managed): Loaded 'C:\Documents and Settings\Johan\Desktop\DownloadManager\DownloadManager\bin\Debug\DownloadManager.exe', Symbols loaded.<br />
A first chance exception of type 'System.NullReferenceException' occurred in DownloadManager.exe<br />
'DownloadManager.vshost.exe' (Managed): Loaded 'C:\WINDOWS\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll', Skipped loading symbols. Module is optimized and the debugger option 'Just My Code' is enabled.<br />
31:10.671 [000A] Start DownloadFile-Thread<br />
31:10.687 [000A] Start DownloadFile-Thread<br />
31:10.703 [000A] Start DownloadFile-Thread<br />
31:10.703 [000A] Start DownloadFile-Thread<br />
31:11.046 [000C] Get the response-stream<br />
31:11.046 [000C] After Get the response-stream<br />
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll<br />
The thread 0x1220 has exited with code 0 (0x0).<br />
31:15.687 [000D] Get the response-stream<br />
31:15.687 [000D] After Get the response-stream<br />
31:19.125 [000F] Get the response-stream<br />
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll<br />
31:19.140 [000F] After Get the response-stream<br />
The thread 0xf10 has exited with code 0 (0x0).<br />
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll<br />
The thread 0x1098 has exited with code 0 (0x0).<br />
A first chance exception of type 'System.Net.WebException' occurred in System.dll<br />
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in mscorlib.dll<br />
The thread 0x13f0 has exited with code 0 (0x0).<br />
The program '[3640] DownloadManager.vshost.exe: Managed' has exited with code 0 (0x0).<br />


The other method you wanted to see:

<br />
        // Calculates information of the download, speed, percent and remaining time<br />
        private void CalculateDownloadingInfo()<br />
        {<br />
            // Calculate speed<br />
            downElapsed = DateTime.Now - downStart;<br />
            secPassed = downElapsed.TotalSeconds;<br />
            kbsec = (strLocal.Length / 1024) / secPassed;<br />
<br />
            // Calculate percent<br />
            int percent = Convert.ToInt32((strLocal.Length * 100) / fileSize);<br />
<br />
            // Calculate remaining time<br />
            long kbLeft = (fileSize - strLocal.Length) / 1024;<br />
            int timeLeft = (int)(kbLeft / kbsec);<br />
<br />
            UpdateDownloadingInfo(percent, kbsec, timeLeft);<br />
        }<br />
<br />
        // Occurs when the download-info is updated<br />
        public event DownloadingEventHandler DownloadingEvent;<br />
        // Called when the download-info is updated<br />
        private void UpdateDownloadingInfo(int percent, double speed, int timeLeft)<br />
        {<br />
            // make sure the are some delegates to call<br />
            // all delegates will be called in the order they were added<br />
            // to the invocation list<br />
            if (DownloadingEvent != null)<br />
                DownloadingEvent(new DownloadingEventArgs(fileSize, strLocal.Length, percent, speed, timeLeft));<br />
        }<br />
<br />
    // Represents the method that will handle the Downloader.DownloadingEvent event.         <br />
    public delegate void DownloadingEventHandler(DownloadingEventArgs e);<br />
    // Class to handle the DownloadingEvent event. <br />
    public class DownloadingEventArgs : EventArgs<br />
    {<br />
        // Size of the file<br />
        private Int64 size;<br />
        // Number of bytes downloaded<br />
        private long bRead;<br />
        // Download percent<br />
        private int pcent;<br />
        // Download-speed<br />
        private int spd;<br />
        // Time left in seconds<br />
        private int tLeft;<br />
<br />
        public DownloadingEventArgs(Int64 fileSize, long bytesRead, int percent, double speed, int timeLeft)<br />
        {<br />
            size = fileSize;<br />
            bRead = bytesRead;<br />
            pcent = percent;<br />
            spd = (int)speed;<br />
            tLeft = timeLeft;<br />
        }<br />
        <br />
        // Get the size of the file <br />
        public Int64 FileSize { get { return size; } }<br />
        // Get the number of bytes that has been read <br />
        public long BytesRead { get { return bRead; } }<br />
        // Get the progress of the download in percent <br />
        public int Percent { get { return pcent; } }<br />
        // Get the current speed of the download in kb/seconds <br />
        public int Speed { get { return spd; } }<br />
        // Get the time left of the download progress <br />
        public int TimeLeft { get { return tLeft; } }<br />
    }<br />

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 
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 

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.