Problems with MenuItem and Threading

Christian B

Member
Joined
Aug 5, 2005
Messages
9
Programming Experience
3-5
Hi,

I have a problem Programming adding different menuitems to my mainForm.MainMenu!

For Example lets see a part of the UpdateMenu function in the MainForm Class

VB.NET:
Expand Collapse Copy
sub UpdateMenu()
if Global.Parameters.MenuIsLoaded then 
	 MainMenu.menuItems.add(Global.Parameters.DynamicMenu)
endif
end sub
This is called for example by onUpdateButton_clicked.

Next there is a sub wich sets the Correct menu
VB.NET:
Expand Collapse Copy
sub setMenu(wichmenu as byte)
	Global.Parameters.DynamicMenu = special.getMenu(wichmenu)
	Global.Parameters.MenuIsLoaded = TRUE
end sub
Now first the working call of setMenu (The test call)
VB.NET:
Expand Collapse Copy
sub cmdLoadMenu_clicked
	setMenu(2)
end sub
But normally set Menu is called by a thread not located in the same Class
for example
VB.NET:
Expand Collapse Copy
sub cmdLoadMenuWithThread_clicked()
	dim t as thread = new thread(Address of loader)
	t.start()
end sub
sub loader()
	setMenu(2)
end sub
An "ArgumentException" is thrown when i call "UpdateMenu" when the Thread Version runs before.

I Have no Idea why this exception is thrown.
Can anyone help me?

Christian
 
Back
Top