0

On rare occasions, my program crashes after its done installing updates. It just gives me a: "ProgramName has stopped responding" error and crashes. I know that it must be something somewhere in the installation method of my windows update install, but i cannot figure out what or where the error is.

Maybe someone with a little more knowledge of the WUAPI.dll can help me out?

The program is run from a USB stick, and I have on occasions been able to "fix" the problem by just moving the program to, like, the desktop, and running it from there, but I want to avoid having to do that. And AFAIK, none of my code actually accesses the usb stick or needs to access the program on the usb stick during the update installation process. Of course I may just be missing something pretty basic..

#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

May also be worth noting i have the following during form closing and form closed events

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

And:

Private Sub WUAPIProgress_FormClosed(sender As Object, e As FormClosedEventArgs) Handles MyBase.FormClosed
    Me.Dispose()
End Sub

Thought i had some error output, unfortunately not after all. It was related to something else.

Edit:

Code catching globally:

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

Edit:

I have traced what may be the main issue.

The program is ran from a USB stick, and if that USB stick is removed before the program is done, it will, for whatever reason, attempt to reach the place where the app was started from (the usb stick) and it then fails, and crashes.

So it seems i will have to have the program copy itself, and then run from a location on the computer. What is strange, however, is that its not always an issue. But on Virtual Machines running Windows 8.1, i observe it on pretty much every go.

I guess i will toy with it a bit more, since i would prefer very much being able to remove the usb stick once the program is up and running.. Puzzles me why it has to have access to the .exe to be able to finish up?

Gematria
  • 105
  • 1
  • 14
  • 1
    "It crashes" is not an appropriate problem description. You *must* write an event handler for the AppDomain.CurrentDomain.UnhandledException event so that unhandled exceptions become diagnosable. Post the exception message and the stack trace you now have to get help here. – Hans Passant Apr 23 '15 at 12:40
  • Ah ok.. Thanks. I will look into this :) Will this also catch the "Program has stopped responding and must be closed"-dialog box? Or is that dialog box a direct result of an exception happening outside a thread, meaning you wont get the usual "Unhandled Exception" dialog? – Gematria Apr 23 '15 at 12:47
  • Yes, you call Environment.Exit() in your event handler after displaying or logging the exception so that this WER dialog is not displayed. – Hans Passant Apr 23 '15 at 12:55
  • Ill work on getting this fixed then and get some data.. Just having some difficulties making it global, but thats for another question :) Thanks for pointing me in the right direction. – Gematria Apr 23 '15 at 13:33
  • Got a bit of data from the error it throws. – Gematria Apr 27 '15 at 13:55
  • Thanks for getting us the error info, which line causes the error? – Jeremy Thompson Apr 27 '15 at 14:16
  • I wish i knew.. Its so rare that i am having difficulties catching it with debugging on. And my error catching for some reason wont display any line nr during this exception, while it does for most other exceptions. – Gematria Apr 27 '15 at 14:17
  • Add tracing, perhaps using the AOP Postsharp library to find out the call stack at leastthen you can narrow down the line number in the last function called and don't use a ShowDialog to show the error just use a log file. – Jeremy Thompson Apr 27 '15 at 22:51
  • So i found the problem. Unfortunately it was due to stupidity on my account. I had some BGWs that ran a timeout function for me, and it was that timeout function that would randomly fail, for whatever reason, ending in the program crashing. – Gematria May 02 '15 at 16:00

1 Answers1

0

There should not be any problems with making it global, just use this code:

Public Shared Sub Main(args As String())
    AppDomain.CurrentDomain.UnhandledException += New UnhandledExceptionEventHandler(AddressOf ApplicationUnhandledException)
End Sub

Private Sub ApplicationUnhandledException(sender As Object, e As UnhandledExceptionEventArgs)
        'Write all the information to help diagnose the problem
End Sub

Then provide Hans &/or I with the info.

Jeremy Thompson
  • 61,933
  • 36
  • 195
  • 321
  • Its in the initial question. Thats the output i can get from it anyway. The code i have catching in applicationevents.vb is in the initial question too in a moment. – Gematria Apr 27 '15 at 14:13