I'm having trouble as well with trying to set a handler for progresschanged event in the download class. I've been trying to follow tutorials on this but no luck and here what I have but it is throwing an error on the AddHandler dclass.ProgressChanged, AddressOf OnProgress line with this "Object reference not set to an instance of an object."
Code:
Option Explicit On
Option Strict On
Imports System
Imports ASQS
Imports ASQS.FileData
Imports ASQS.DownloadClass
Imports ASQS.ManagerClass
Public Class Form1
Public WithEvents dclass As DownloadClass
Public WithEvents sas As New ManagerClass
Public Delegate Sub ProgressChangedEventHandler(ByVal file As String, ByVal speed As String, ByVal percent As Integer)
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim where As New FileData
AddHandler dclass.ProgressChanged, AddressOf OnProgress
sas.AutoDownload = True
sas.MaxDownloads = 2
where.SaveTo = "C:\Downloads\test.mp3"
where.URL = "http://www.site.com/a.mp3"
'MsgBox(where.FileName)
'MsgBox(where.FilePath)
sas.Add(where)
'sas.RunList()
End Sub
Public Sub OnProgress(ByVal file As String, ByVal speed As String, ByVal percent As Integer) Handles dclass.ProgressChanged
If Me.InvokeRequired Then
Me.Invoke(New ProgressChangedEventHandler( _
AddressOf OnProgress _
), New Object() {percent})
Else
Me.ProgressBar1.Value = percent
End If
End Sub
End Class
Here is the detailed exception:
Code:
System.NullReferenceException was unhandled
Message=Object reference not set to an instance of an object.
Source=pmr
StackTrace:
at WindowsApplication1.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\pmr\pmr\Form1.vb:line 17
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at WindowsApplication1.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException:
Thanks