0

I have a WinForms application in VB.net with a NotifyIcon with ContextMenu attached. For some reason when I click the menu item to set the main form as Me.TopMost = false, then copy the batch file to the PC and run it, the NotifyIcon seems to get disposed (no longer appears in system tray). This only appears to happen intermittently.... I have no idea what could be causing this.

The reason that I am thinking that the NotifyIcon is disposed is because if I add a readerNotify.Visible = True after the operation the icon still does not re-appear. See below for the code

     Private Sub ResetWindowsUpdateComponentsToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ResetWindowsUpdateComponentsToolStripMenuItem.Click
        'Adds Windows Update Components reset batch file to ProgramData and runs the file
        Dim fileContent As String = My.Resources.WindowsUpdate_Components_Reset
        Dim filename As String = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + "\WUCR.bat"

        Me.TopMost = False
        clearWUCache()

        My.Computer.FileSystem.WriteAllText(filename, fileContent, False, System.Text.Encoding.ASCII)

   '**WHERE NOTIFYICON SEEMS TO DIE**

        Dim objProcess As Process = New Process
        objProcess.StartInfo.FileName = filename
        objProcess.Start()
        objProcess.WaitForExit()

        prgBarTemps.Value = 100
        lblStatus.Text = "Windows Update components reset successfully!"

        Me.TopMost = True
    End Sub

    Private Sub clearWUCache()
        Dim wuCacheFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.Windows) & "\SoftwareDistribution\Download"
        Try
            WebFixProcesses.deleteFolders(wuCacheFolder)
            WebFixProcesses.deleteFiles(wuCacheFolder)
        Catch ex As Exception
            MsgBox(ex.Message)
            Dim wuCacheDirect As String = "C:\Windows\SoftwareDistribution\Download"
            WebFixProcesses.deleteFolders(wuCacheDirect)
            WebFixProcesses.deleteFiles(wuCacheDirect)
            lblStatus.Text = "Press a button to fix problems"
        End Try

    End Sub

I must be doing something wrong here in the way I am setting up the batch file in conjunction with setting Me.TopMost = False or something like that. Any help on this is greatly appreciated!


EDIT:

Here is some additional info from my Form.Designer InitializeComponent() method on the NotifyIcon.

    Private Sub InitializeComponent()

'Have omitted other controls    

        Me.readerNotify = New System.Windows.Forms.NotifyIcon(Me.components)

        'readerNotify
                '
                Me.readerNotify.ContextMenuStrip = Me.ContextMenu
                Me.readerNotify.Icon = CType(resources.GetObject("readerNotify.Icon"), System.Drawing.Icon)
                Me.readerNotify.Text = "WebFix"
                Me.readerNotify.Visible = True

     End Sub

     Public WithEvents readerNotify As System.Windows.Forms.NotifyIcon
ganjeii
  • 1,168
  • 1
  • 15
  • 26
  • Are you sure the icon is just not going into the **show hidden icons** button if you don't touch it long enough? – Thraka Sep 11 '15 at 15:57
  • @Thraka, yup I double checked the hidden icons area by clicking that up arrow next to the time/ date, notification area. It is gone from there as well. But yes I am aware that it is demoted after 45 seconds to this hidden icons area or sometime around that. The only way I can seem to get it back is by re-launching the application. – ganjeii Sep 11 '15 at 15:59
  • Maybe share some more info like some of your form config, the settings you have for the notify icon .. etc – Thraka Sep 11 '15 at 17:48
  • This post is not related to tag [tag:batch-file], is it? – aschipfl Sep 11 '15 at 21:43

0 Answers0