Menu doesn't appear ...

G

Gita George

Consider this code:

Public I As New NotifyIcon

Public mnuPopUp As New ContextMenu

Public WithEvents mnuSetari As New MenuItem

Public WithEvents mnuExit As New MenuItem

Sub Main()

mnuSetari.Index = 0

mnuSetari.Text = "SETARI"

mnuExit.Index = 0

mnuExit.Text = "Exit"

mnuPopUp.MenuItems.Add(mnuSetari)

mnuPopUp.MenuItems.Add(mnuExit)

I.Text = "NO NEW MAIL"

I.ContextMenu = mnuPopUp

I.Visible = True

While Not (check_timer Is Nothing)

System.Threading.Thread.Sleep(100)

End While

End Sub

When I press my mouse right buton the menu mnuPopUp doesn;t show up.

Can you provide me a workaround for this problem ?

Thanks in advance ...
 
C

Cor

Hi Gita,

That is why I did show you that timer code, your application is frozen now.
But you can do it using the code you are using now also.

Just add

While Not (check_timer Is Nothing)
System.Threading.Thread.Sleep(100)
application.doevents
End While
Cor


While Not (check_timer Is Nothing)

System.Threading.Thread.Sleep(100)

End While
 
F

Fergus Cooney

Hi Gita, Cor,

I'm pretty sure that DoEvents won't do anything unless the message pump is
working so, going back to my last post, use Application.Run.

[And now we know what that Sub Main was all about] ;-)

Regards,
Fergus
 
H

Herfried K. Wagner [MVP]

* "Gita George said:
Public I As New NotifyIcon

Public mnuPopUp As New ContextMenu

Public WithEvents mnuSetari As New MenuItem

Public WithEvents mnuExit As New MenuItem

Sub Main()

mnuSetari.Index = 0

mnuSetari.Text = "SETARI"

mnuExit.Index = 0

mnuExit.Text = "Exit"

mnuPopUp.MenuItems.Add(mnuSetari)

mnuPopUp.MenuItems.Add(mnuExit)

I.Text = "NO NEW MAIL"

I.ContextMenu = mnuPopUp

I.Visible = True


While Not (check_timer Is Nothing)

    System.Threading.Thread.Sleep(100)

End While

Why not simply use 'Application.Run' instead of the loop?!

--
Herfried K. Wagner
MVP · VB Classic, VB.NET
<http://www.mvps.org/dotnet>

<http://www.plig.net/nnq/nquote.html>
 
C

Cor

Hi Gita,

My message in this thread was totaly wrong.
I did not look at your code, just at the error and what is mostly the reason of it.

When you do
dim check_timer as system.timers.timer
While Not (check_timer Is Nothing)
System.Threading.Thread.Sleep(100)
End While

I think that will never sleep at all

And with
dim check_timer as new system.timers.timer
While Not (check_timer Is Nothing)
System.Threading.Thread.Sleep(100)
End While
I think this will never stop

My advice, look at the code from fergus and use the timer I gave you in my example, or make a timerloop yourself with that while not code, but don't use that timer to stop it.
(An advice Fergus did gave you also in that thread).

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top