[VB] TargetInvocationException
Ciao a tutti!
Dopo quasi un'anno di C++ mi sono buttato sul VB.
ho un problema nel seguente script che aggiorna il programma da me creato.
Codice:
Imports System.Windows.Forms
Imports System.Net
Imports System.IO
'Imports System.Text
Public Class Aggiornamento
Public WithEvents TCP As New System.Net.WebClient
Public Sub PrgChngd(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles TCP.DownloadProgressChanged
progresso.Minimum = 0
progressoLabel.Text = e.ProgressPercentage() & "%" 'restituisce la percentuale del download
progresso.Maximum = e.TotalBytesToReceive() 'restituisce il numero dei Byte da ricevere
progresso.Value = e.BytesReceived()
End Sub
Private Sub PrgComplete(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs) Handles TCP.DownloadFileCompleted
If e.Cancelled = True Then
'il download è stato cancellato
Else
'il download è stato completato
progresso.Visible = False
progressoLabel.Visible = False
Dim file_exe
file_exe = Shell("c:\m93spnl_last.exe", vbMaximizedFocus)
End If
End Sub
Private Sub Cancel_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel_Button.Click
Me.Close()
End Sub
Private Sub Aggiornamento_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Cursor = Cursors.WaitCursor
Application.DoEvents()
Try
' Make a WebClient.
Dim web_client As WebClient = New WebClient
' Get the indicated URI.
Dim response As Stream = web_client.OpenRead("http://matt93.altervista.org/vb8/last_version.txt")
' Read the result.
Dim stream_reader As New IO.StreamReader(response)
UltimaVersione.Text = "Ultima Versione Disponibile: " + stream_reader.ReadToEnd()
' Close the stream reader and its underlying stream.
stream_reader.Close()
Catch ex As Exception
UltimaVersione.Text = "Ultima Versione Disponibile: N/D"
Errori.Text = "Errore Di connessione al server: " + vbCrLf + ex.Message
End Try
Me.Cursor = Cursors.Default
End Sub
Private Sub Aggiorna_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Aggiorna_Button.Click
progresso.Visible = True
progressoLabel.Visible = True
TCP.DownloadFileAsync(New Uri("http://matt93.altervista.org/vb8/last_version.exe"), "c:\m93spnl_last.exe")
End Sub
End Class
in poche parole appena deve partire l'esecuzione del file scaricato mi da target exception.... cosa vuol dire???