【发布时间】:2015-07-01 11:28:10
【问题描述】:
在极少数情况下,我的程序在完成安装更新后会崩溃。它只是给了我一个:“ProgramName 已停止响应”错误并崩溃。我知道它一定是我的 Windows 更新安装的安装方法中的某个地方,但我无法弄清楚错误是什么或在哪里。
也许对 WUAPI.dll 有更多了解的人可以帮助我?
该程序是从 U 盘运行的,有时我可以通过将程序移动到桌面(例如桌面)并从那里运行它来“解决”问题,但我想避免不得不这样做去做。而且 AFAIK,在更新安装过程中,我的代码实际上都没有访问 U 盘或需要访问 U 盘上的程序。当然,我可能只是缺少一些非常基本的东西..
#Region "Installation method"
Public Sub iInstallation()
Progression = "UpdateInstall"
iUpdateInstaller = TryCast(UpdateSession.CreateUpdateInstaller(), IUpdateInstaller)
iUpdateInstaller.Updates = NewUpdatesCollection
iInstallationJob = iUpdateInstaller.BeginInstall(New iUpdateInstaller_onProgressChanged(Me), New iUpdateInstaller_onCompleted(Me), New iUpdateInstaller_state(Me))
End Sub
Public Sub iInstallationComplete()
Try
Progression = "InstallComplete"
iDownloadJob.CleanUp()
iInstallationResult = iUpdateInstaller.EndInstall(iInstallationJob)
InvokeUIChangeText = "Installation Complete..."
InvokeUIChange()
If iInstallationResult.ResultCode = OperationResultCode.orcSucceeded Or iInstallationResult.ResultCode = OperationResultCode.orcSucceededWithErrors Then
message = "Installation done. " & iInstallationJob.Updates.Count & " Updates installed"
caption = "Installation Successfull"
buttons = MessageBoxButtons.OK
ikon = MessageBoxIcon.Information
MessageBox.Show(message, caption, buttons, ikon)
Me.Close()
Else
message = "One or more installations failed to install."
caption = "Installation failure"
buttons = MessageBoxButtons.OK
ikon = MessageBoxIcon.[Error]
MessageBox.Show(message, caption, buttons, ikon)
Me.Close()
End If
Catch err As Exception
MsgBox(err.Message)
End Try
End Sub
Public Class iUpdateInstaller_onProgressChanged
Implements IInstallationProgressChangedCallback
Private form1 As WUAPIProgress
Public Sub New(mainForm As WUAPIProgress)
Me.form1 = mainForm
End Sub
Public Sub Invoke(installationJob As IInstallationJob, e As IInstallationProgressChangedCallbackArgs) Implements IInstallationProgressChangedCallback.Invoke
Dim x As Integer = e.Progress.CurrentUpdatePercentComplete
form1.Invoke(Sub()
form1.Action.Text = "Installere opdatering " & e.Progress.CurrentUpdateIndex + 1 & "/" & installationJob.Updates.Count & " " & installationJob.Updates.Item(e.Progress.CurrentUpdateIndex + 1).Title
form1.ProgressBar1.Value = x
form1.Refresh()
End Sub)
End Sub
End Class
Public Class iUpdateInstaller_onCompleted
Implements IInstallationCompletedCallback
Private form1 As WUAPIProgress
Public Sub New(mainForm As WUAPIProgress)
Me.form1 = mainForm
End Sub
Public Sub Invoke(installationJob As WUApiLib.IInstallationJob, callbackArgs As IInstallationCompletedCallbackArgs) Implements IInstallationCompletedCallback.Invoke
form1.iInstallationComplete()
End Sub
End Class
Public Class iUpdateInstaller_state
Private form1 As WUAPIProgress
Public Sub New(mainForm As WUAPIProgress)
Me.form1 = mainForm
msgbox("Starting installation")
End Sub
End Class
#End Region
可能还值得注意的是,我在表单关闭和表单关闭事件期间有以下内容
Private Sub WUAPIProgress_FormClosing(sender As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
Try
Dim AutoUpdate = My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update\", True)
AutoUpdate.SetValue("AUOptions", 4)
If Progression = "UpdateSearch" Or Progression = "SearchComplete" Then
iSearchJob.RequestAbort()
ElseIf Progression = "UpdateDownload" Or Progression = "UpdateComplete" Then
iDownloadJob.RequestAbort()
ElseIf Progression = "UpdateInstall" Or Progression = "InstallComplete" Then
iInstallationJob.RequestAbort()
End If
Catch err As Exception
MsgBox(err.Message)
End Try
End Sub
还有:
Private Sub WUAPIProgress_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
Me.Dispose()
End Sub
以为我有一些错误输出,不幸的是毕竟不是。它与其他东西有关。
编辑:
全局代码捕获:
Namespace My
' The following events are available for MyApplication:
'
' Startup: Raised when the application starts, before the startup form is created.
' Shutdown: Raised after all application forms are closed. This event is not raised if the application terminates abnormally.
' UnhandledException: Raised if the application encounters an unhandled exception.
' StartupNextInstance: Raised when launching a single-instance application and the application is already active.
' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
Partial Friend Class MyApplication
Private Delegate Sub SafeApplicationThreadException(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs)
Private Sub ShowDebugOutput(ByVal ex As Exception)
Dim frmD As New frmDebug()
frmD.rtfError.AppendText(ex.ToString())
frmD.ShowDialog()
Environment.Exit(0)
End Sub
Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
AddHandler System.Windows.Forms.Application.ThreadException, AddressOf app_ThreadException
AddHandler AppDomain.CurrentDomain.UnhandledException, AddressOf AppDomain_UnhandledException
End Sub
Private Sub app_ThreadException(ByVal sender As Object, ByVal e As Threading.ThreadExceptionEventArgs)
If MainForm.InvokeRequired Then
MainForm.Invoke(New SafeApplicationThreadException(AddressOf app_ThreadException), New Object() {sender, e})
Else
ShowDebugOutput(e.Exception)
End If
End Sub
Private Sub AppDomain_UnhandledException(ByVal sender As Object, ByVal e As UnhandledExceptionEventArgs)
ShowDebugOutput(DirectCast(e.ExceptionObject, Exception))
End Sub
Private Sub MyApplication_UnhandledException(sender As Object, e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
ShowDebugOutput(e.Exception)
End Sub
End Class
End Namespace
编辑:
我已经找到了可能的主要问题。
程序从 U 盘运行,如果该 U 盘在程序完成之前被移除,无论出于何种原因,它都会尝试到达启动应用程序的位置(U 盘)并且它然后失败,然后崩溃。
所以看来我必须让程序自行复制,然后从计算机上的某个位置运行。 然而,奇怪的是,它并不总是一个问题。但是在运行 Windows 8.1 的虚拟机上,我几乎每次都会观察到它。
我想我会更喜欢它,因为我非常希望能够在程序启动并运行后移除 USB 记忆棒。我不明白为什么它必须有权访问 .exe能完成吗?
【问题讨论】:
-
“它崩溃了”不是一个合适的问题描述。您必须为 AppDomain.CurrentDomain.UnhandledException 事件编写事件处理程序,以便可以诊断未处理的异常。在此处发布您现在必须获得帮助的异常消息和堆栈跟踪。
-
啊好的..谢谢。我会调查这个:)这是否也会捕获“程序已停止响应并且必须关闭”对话框?还是该对话框是线程外部发生异常的直接结果,这意味着您不会得到通常的“未处理异常”对话框?
-
是的,您在显示或记录异常后在事件处理程序中调用 Environment.Exit() 以便不显示此 WER 对话框。
-
我会努力解决这个问题并获取一些数据。只是在使其全球化时遇到了一些困难,但这是另一个问题 :) 感谢您为我指明正确的方向。
-
从它抛出的错误中得到了一些数据。
标签: vb.net windows-update wuapi