473,394 Members | 1,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Invoking control from different thread

I've got a combobox that I am getting updated data for in real time and
need to clear out the values and reload it with the new data. I keep
getting an error that I can't access the control because it was created
from a different thread. I've been trying to figure out how to do this
using Invoke/Delegates, but am greatly confused and stuck. Any help
would be greatly appreciated. Thanks!
All I need is this, but how do I do it using an invoke/delegates?!? :

comboBox.Items.Clear();
for (int i = 0; i < count; i++)
comboBox.Items.Add(i);

Thanks again!

David

Nov 17 '05 #1
2 5172
"david s" <ph******@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
I've got a combobox that I am getting updated data for in real time and
need to clear out the values and reload it with the new data. I keep
getting an error that I can't access the control because it was created
from a different thread. I've been trying to figure out how to do this
using Invoke/Delegates, but am greatly confused and stuck. Any help
would be greatly appreciated. Thanks!
All I need is this, but how do I do it using an invoke/delegates?!? :

comboBox.Items.Clear();
for (int i = 0; i < count; i++)
comboBox.Items.Add(i);

Thanks again!

David


Something like this?

delegate void MyDel(int max);

void Foo()
{
MyDel d = delegate(int max)
{
comboBox.Items.Clear();
for (int i = 0; i < max; i++)
comboBox.Items.Add(i);
};
comboBox.BeginInvoke(d, 42);
}

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk
Nov 17 '05 #2
Great thanks it worked! it makes so much more sense now to me!

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Pierre | last post by:
I know that we should use the Invoke method to access the methods of a windows control when we are on a different thread than the main UI thread. But what about properties? They are internally...
25
by: MuZZy | last post by:
Hi, I'm currently rewriting some functionality which was using multithredaing for retrieving datasets from database and updating a grid control. I found that the grids (Infragistics UltraGrid,...
1
by: gemartin | last post by:
Here's my question: I have Windows Forms app. Suppose the user clicks on the "Processing" button on the UI. The UI thread then starts processing. During this processing another thread calls...
4
by: Claire | last post by:
Visual Studio 2003 I have a thread running a small timeout. Rather than defining my own delegate I decided to be lazy and use a standard EventHandler delegate When OnReadMessageTimeout is...
6
by: DaTurk | last post by:
I know in a WinForm you can check if an Invoke is inquired and invoke a method on the main thread. But can you do this in a class? Can I call Invoke(someMethod) in my asynch event handler? And...
3
by: Thijs | last post by:
Hello everybody, I´ve got a problem that´s slightly complicated (at least to me it seems) so I will try to state it as clearly as possible. At a certain point in time, I start a second thread...
0
by: Jon | last post by:
Hi, "THREAD_UI" = thread under which the UI controls were created. "THREAD_XX" = another thread. "FUNC_UI" = function that needs to run on THREAD_UI. From THREAD_XX I need to start the...
2
by: =?Utf-8?B?SmltIE93ZW4=?= | last post by:
Hi John, Hopefully this post will find its way back to you - or perhaps be answered by someone else. As I mentioned in my last post on the earlier portion of this thread, changing the...
3
by: Steve | last post by:
Hi All I am using VB.net 2008 and use timer controls within my applications Question Does the code in a Timer control.tick event run on a different thread to the main Application thread (UI...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.