toolBar updates

  • Thread starter Thread starter MDB
  • Start date Start date
M

MDB

Hello All, I am trying to update a toolbar in a form that is active and
when I do, it locks up the application. Anyone know what I can do to avoid
this?

That application will lock up on this statement

toolBar1.Buttons.Clear();



TIA
 
Is this method being called from the main thread? If not Try something like
this.

----------------------------------------------

Sub ClearToolbar()
Me.ToolBar1.Invoke(New EventHandler(AddressOf ClearToolbar))
End Sub

Sub ClearToolbar(ByVal sender As Object, ByVal e As EventArgs)
Me.ToolBar1.Buttons.Clear()
End Sub
 
You are right. I am calling a function that updates a form from a sub
thread. Everything stepped through fine until it got to where it updates
what is displayed to the user. All I really want to do is change the image
index of one of the buttons. Any suggestions on how to do this from a
second thread? It appears that I need to use some type of delegate.
 
Yes, anytime a program updates the ui it should join the main thread. This
is accomplished by invoking EventHandlers like you see in this code.

You may want to check out the ControlInvoker object from MS's QuickStart
examples (url unknown, but you can find it somewhere on www.gotdotnet.com).
The ControlInvoker allows you to call EventHandlers with arguments since this
is not directly supported in CF.NET.

If you are still running into problems, please post a small sample of the
code so we may serve you better.
 
Okay, I am getting confused now. I think I have been looking a too many
examples which all do it differenlty (at least I think). Here is what my
function looks like that I am trying to call from a background thread.. The
background thread is a loop that looks for a wifi connection every few
seconds. If the status of the connection changes, it updates a global bool
value and then calls this function.

public void LoadMenu()
{
toolBar1.Buttons.Clear();

toolBar1.ImageList = MyApp.Classes.Globals.gilTBar;

if(MyApp.Classes.Globals.gblWiFiSignal)
{
MyApp.Classes.Globals.gbtnSignal.ImageIndex = 21;
}
else
{
MyApp.Classes.Globals.gbtnSignal.ImageIndex = 22;
}

toolBar1.Buttons.Add(MyApp.Classes.Globals.gbtnSignal);
}


I try to "invoke" this with this:

MyApp.Classes.Globals.gfrmOrders.Invoke(MyApp.Classes.Globals.gfrmOrders.Loa
dMenu());


Thanks For All Of Your Help!
 
Well after playing around with it all day I have found that using the
delegates, I can change anything on the page with out a problem except the
toolbar. As soon as I do any thing with the tool bar, the applications
locks up. Any ideas why the toolbar would cause the app to lock up?
 
Back
Top