Community
Showing results for 
Search instead for 
Do you mean 
Reply

Cross-thread operation not valid: Control 'ACT! Toolbar' accessed from a thread other than the thread it was created on

New Member
Posts: 2
Country: United_Kingdom

Cross-thread operation not valid: Control 'ACT! Toolbar' accessed from a thread other than the thread it was created on

I am getting "Cross-thread operation not valid: Control 'ACT! Toolbar' accessed from a thread other than the thread it was created on" error when i am trying to change toolbar menu, I know the cause of the issue but i cant fix it with the regular control invoke code, Please let me know if there is anything else i can do it to prevent it.

 

Thanks in advance.

 

var toolbar = _actApplication.Explorer.CommandBarCollection["ACT! Toolbar"];

if
(toolbar.InvokeRequired)//no such method available { toolbar.Invoke(new MethodInvoker(() => { DoSomething(); })); } else { toolbar.Visible = true; }
Nickel Contributor
Posts: 175
Country: USA

Re: Cross-thread operation not valid: Control 'ACT! Toolbar' accessed from a thread other than the thread it was created on

I'm presuming that the code you posted is the code that has the issue. While, I haven't used the same method you are, it does look like it would work if an Invoke is required. However, I believe that your else statement will have an issue. When you are trying to do anything with a UI object on a different thread, you must marshal/invoke it from the calling thread. So, that would mean that you have to invoke a method to set the visibilty to true.

 

The only other thing that comes to mind is that you may have created the _actApplication object in your new thread. If that is the case, I don't think your code will ever work properly, as there is nothing tying you back to the UI thread. Hopefully this helps.

New Member
Posts: 2
Country: United_Kingdom

Re: Cross-thread operation not valid: Control 'ACT! Toolbar' accessed from a thread other than the thread it was created on

The code was just a reference I was not setting visibility there, furthere can you please let mek now how can i create actapplication object in other thread, I have only a single class that using IPlugin which is used for retrieving actApplication instance on OnLoad Event.

 

I have also tried creating instance

 

ActApplication _actApplication = new ActApplication();

 but in this code I am not able to access Connect menu, getting null reference