Programmatically created ContextMenu

shawne

Well-known member
Joined
Feb 22, 2006
Messages
103
Location
Pennsylvania
Programming Experience
10+
Given the below piece of code, why after the first right click to bring up the context menu, the menu no longer comes up? It trys (flashes and disappears) but will not remain. Thanks!

VB.NET:
    Public ContextMenu1 As New ContextMenu
    Public MenuItem1 As New MenuItem
    Public MenuItem2 As New MenuItem

    Sub main()
        noticon.Icon = New Icon("ndico.ico")
        noticon.Visible = True

        MenuItem1.Text = "&Abort"
        MenuItem2.Text = "&Pause"

        ContextMenu1.MenuItems.Add(MenuItem1)
        ContextMenu1.MenuItems.Add(MenuItem2)

        AddHandler MenuItem1.Click, AddressOf menuitem1_Click
        AddHandler MenuItem2.Click, AddressOf menuitem2_Click

        noticon.ContextMenu = ContextMenu1

        myThread.Start()
    End Sub
    Public Sub menuitem1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        myThread.Abort()
        End
    End Sub
    Public Sub menuitem2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        If myThread.ThreadState = ThreadState.Running Then
            MenuItem2.Text = "&Resume"
            myThread.Suspend()
            noticon.Text = "Update suspended!"
        Else
            MenuItem2.Text = "&Pause"
            myThread.Resume()
            noticon.Text = "Resuming..."
        End If
    End Sub
 
Last edited:
What's the method myThread executes when it starts?

Im guessing that noticon is a NotifyIcon - and updater is another thread? What is this thread running?

mafro
 
myThread uses WMI to collect information off of PC clients and updates an SQL database with the information. After the update is finished, it looks for new clients that were added to the network since the last update.

noticon as you guessed is a notification icon, along with the context menu, it is the only interface i need & want for this application.

updater was the original name of myThread, i just missed renaming it (my bad)
 
Nope. The only other change to the UI during runtime is the noticon.text is updated to reflect what record is being updated and the % complete.

VB.NET:
                     noticon.Text = "Updateing...." & Int((rec / totalRecords) * 100) & "% " & rs.Fields("pc").Value
 
Back
Top