先运行UPDATE.EXE的时候先关闭主程序的EXE
不会的.你用一个callback,异步调用啊...先用WEBCLINET类从SERVER上将要下载的文件下载到客户机上,记住不要跟现有的主程序文件名同名,然后等下载完毕后就会执行CALLBACK的过程,这个过程就将原来的主程序文件删除,再将新下回来的改成主程序文件名,并运行它.关闭UPDATE.EXE就可以了.

解决方案 »

  1.   

    Delegate Sub UPgrade1()
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click        '  Timer1.Enabled = True : Timer1.Interval = 1000 : ProgressBar1.Maximum = 10000 : i = 0
            Me.Button1.Visible = False
            Dim Pro As New UPgrade1(AddressOf Me.UpGradeFunction)
            Dim r As IAsyncResult
            '异步调用并显示结果
            r = Pro.BeginInvoke(New AsyncCallback(AddressOf ShowResult), Pro)
        End Sub
        Delegate Sub jg()
        Sub ShowResult(ByVal U As IAsyncResult)
            Dim rjg As New jg(AddressOf Me.AfterSucces)
            Me.Button1.Invoke(rjg)
        End Sub
        Sub AfterSucces()
            Cursor.Current = Cursors.Default
            Label1.Text = "下载成功!重新运行程序"
            If Not File.Exists(Application.StartupPath & "\test1.exe") Then
                MsgBox("下载文件不成功,网络有问题!请重试!", MsgBoxStyle.Exclamation + MsgBoxStyle.OKOnly, "提示")
                Button1.Visible = True
                Label1.Text = ""
                Exit Sub
            End If
            If File.Exists(Application.StartupPath & "\test.exe") Then
                File.Delete(Application.StartupPath & "\test.exe")
            End If
            If File.Exists(Application.StartupPath & "\test1.exe") Then
                Rename("test1.exe", "test.exe")
                Process.Start(Application.StartupPath & "\test.exe")
            End If
            Me.Close()
            Application.Exit()
            End    End Sub
        Sub UpGradeFunction()
            Try
                Cursor.Current = Cursors.Hand
                Dim Filename As String = "test.exe"
                Dim DownUrl As String = "http://" & serverName & "/download/capital/" & Filename
                Dim myStringWebResource As String = DownUrl
                Dim myWebClient As New WebClient()
                myWebClient.DownloadFile(myStringWebResource, Application.StartupPath & "\test1.exe")
                myWebClient.Dispose()
            Catch ex As Exception
                MsgBox(Err.Description & " " & Err.Number, MsgBoxStyle.Critical + MsgBoxStyle.OKOnly, "提示")
                Cursor.Current = Cursors.Default
                Exit Sub
            End Try
            Cursor.Current = Cursors.Default
        End Sub
      

  2.   

    有没有C#的代码?我看不太懂VB.Net的代码。谢谢。
      

  3.   

    找到了。谢谢二位。 以下示例使用 CancelEventArgs 和 CancelEventHandler 来处理 Form 的 Closing 事件。此代码假定已经创建具有类级别 Boolean 变量(名为 myDataIsSaved)的 Form。[Visual Basic] 
    ' Calls this method from the InitializeComponent() method of your form.
    Private Sub OtherInitialize()
        AddHandler Me.Closing, AddressOf Me.Form1_Cancel
        Me.myDataIsSaved = New Boolean()
        Me.myDataIsSaved = True
    End Sub 'OtherInitializeProtected Sub Form1_Cancel(sender As Object, e As CancelEventArgs)
        If Not myDataIsSaved Then
            e.Cancel = True
            MessageBox.Show("You must save first.")
        Else
            e.Cancel = False
            MessageBox.Show("Goodbye.")
        End If
    End Sub 'Form1_Cancel
    [C#] 
    // Calls this method from the InitializeComponent() method of your form
        private void OtherInitialize() {
           this.Closing += new CancelEventHandler(this.Form1_Cancel);
           this.myDataIsSaved = new Boolean();
           this.myDataIsSaved = true;
        }
        protected void Form1_Cancel (Object sender, CancelEventArgs e) {
           if (!myDataIsSaved) {
              e.Cancel = true;
              MessageBox.Show("You must save first.");
           }
           else {
              e.Cancel = false;
              MessageBox.Show("Goodbye.");
           }
        }
    [C++, JScript] 没有可用于 C++ 或 JScript 的示例。若要查看 Visual Basic 或 C# 示例,请单击页左上角的语言筛选器按钮 。