If I select a job that is over 2GB in size and click on “Job Details” I get an exception. It seems like an Int32 is used when an Int64 or a Decimal should be used.
Error details:
System.OverflowException: Value was either too large or too small for an Int32.
at System.Decimal.ToInt32(Decimal d)
at System.Convert.ToInt32(Decimal value)
at WinBITS.Form1.ShowDetails()
at WinBITS.Form1.JobList_DoubleClick(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnDoubleClick(EventArgs e)
at System.Windows.Forms.ListView.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2407
CodeBase: file:///c:/windows/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
WinBITS
Assembly Version: 1.0.2340.32679
Win32 Version: 1.0.2340.32679
CodeBase: file:///C:/Program%20Files/WinBITS/WinBITS.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2407
CodeBase: file:///c:/windows/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
Microsoft.VisualBasic
Assembly Version: 7.0.5000.0
Win32 Version: 7.10.6001.4
CodeBase: file:///c:/windows/assembly/gac/microsoft.visualbasic/7.0.5000.0__b03f5f7f11d50a3a/microsoft.visualbasic.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase: file:///c:/windows/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
BackgroundCopyManager
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Program%20Files/WinBITS/BackgroundCopyManager.DLL
----------------------------------------
Microsoft.VisualBasic.resources
Assembly Version: 7.0.5000.0
Win32 Version: 7.10.3052.4
CodeBase: file:///c:/windows/assembly/gac/microsoft.visualbasic.resources/7.0.5000.0_sv_b03f5f7f11d50a3a/microsoft.visualbasic.resources.dll
----------------------------------------
SIDUtilities
Assembly Version: 1.0.1192.3910
Win32 Version: 1.0.1192.3910
CodeBase: file:///C:/Program%20Files/WinBITS/SIDUtilities.DLL
----------------------------------------
Logged In: YES
user_id=1948095
Originator: NO
The problem is that the progress bar MaxValue property is an int32. In the ShowDetails sub within Form1, the following line is the source of the error.
If BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal < 100000000000 Then frmInfo.ProgressBar1.Maximum = BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal
Instead of a hard-coded 100000000000, it should check for System.Int32.MaxValue like
If BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal < System.Int32.MaxValue Then frmInfo.ProgressBar1.Maximum = BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal
Fixing this only shifts the error a couple of lines. Inside the next If statement is
frmInfo.ProgressBar1.Value = BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTransferred
If BytesTotal >= System.Int32.MaxValue, the MaxValue on the progress bar may still be 100. Setting the Value property to anything above that will cause another exception.
Since the actual Value and MaxValue are not accessible to the user, restructuring the If statement to leave the MaxValue at 100 and calculating the Value as a percent, which is done already for the Text property, is a quick fix which worked for me.
Hence, this block:
If BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal < 100000000000 Then frmInfo.ProgressBar1.Maximum = BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal
If BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal > 0 Then
frmInfo.txtPercent.Text = Mid(BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTransferred / BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal * 100, 1, 4) & " %"
frmInfo.ProgressBar1.Value = BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTransferred
End If
Becomes:
If BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal > 0 Then
frmInfo.txtPercent.Text = Mid(BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTransferred / BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal * 100, 1, 4) & " %"
frmInfo.ProgressBar1.Maximum = 100
frmInfo.ProgressBar1.Value = BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTransferred / BITS.GetListofJobs.Item(SelectedIndex).Progress.BytesTotal * 100
End If