473,811 Members | 2,756 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

More Multithread and UI Forms Update

Hi,

I've read "Cybertof"' s thread (04/19/04) & the article he provided in a link
about accessing UI elements from a thread that did not create them. What the
authors are saying makes plenty of sense. However, using the control's
Invoke method handles calling it's methods, but what about accessing the
control's properties from another thread? What's the proper way to do that?

--
John C. Bowman
Software Engineer
Thermo Electron Scientific Instruments Div.
<Remove this before reply> jo*********@the rmo.com
Nov 16 '05 #1
5 1417
<"John Bowman" <<Remove this before reply> jo*********@the rmo.com>>
wrote:
I've read "Cybertof"' s thread (04/19/04) & the article he provided in a link
about accessing UI elements from a thread that did not create them. What the
authors are saying makes plenty of sense. However, using the control's
Invoke method handles calling it's methods, but what about accessing the
control's properties from another thread? What's the proper way to do that?


Again, through a delegate and Invoke. You shouldn't access the property
directly from a non-UI thread.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Jon,

Thanks for the quick reply. I kind of suspected that would be the answer
<g>. However, I don't understand (code wise) how to use Invoke to access a
property. I understand how to use it for accessing a method. Do you just
treat the property of interest as if it's a method that has no arguments?
Any example code?

TIA,

John
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
<"John Bowman" <<Remove this before reply> jo*********@the rmo.com>>
wrote:
I've read "Cybertof"' s thread (04/19/04) & the article he provided in a link about accessing UI elements from a thread that did not create them. What the authors are saying makes plenty of sense. However, using the control's
Invoke method handles calling it's methods, but what about accessing the
control's properties from another thread? What's the proper way to do
that?
Again, through a delegate and Invoke. You shouldn't access the property
directly from a non-UI thread.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 16 '05 #3
<"John Bowman" <<Remove this before reply> jo*********@the rmo.com>>
wrote:
Thanks for the quick reply. I kind of suspected that would be the answer
<g>. However, I don't understand (code wise) how to use Invoke to access a
property. I understand how to use it for accessing a method. Do you just
treat the property of interest as if it's a method that has no arguments?
No - you would have to create a delegate which accessed the property,
and invoke that delegate.
Any example code?


Well, just:

delegate string StringReturning Delegate();

string GetLabelText()
{
return label.Text;
}

....

myControl.Invok e
(new StringReturning Delegate(myCont rol.GetLabelTex t());

should work.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4
Hi John,

You can use a method to access a property. This would be a special method
that you call thru Invoke and this method sets or gets the property. The
other way is to create a delegate to invoke the 'get' or 'set' accessor of
the property directly. Hoewever IMHO the first is more easy to use. For
invoking the accessor directly you can follow this link
http://groups.google.ca/groups?hl=en...sor%2Bstoitcho
Look for my post, which is last in the thread.
--
HTH
B\rgds
Stoitcho Goutsev (100) [C# MVP]

"John Bowman jo*********@the rmo.com>" <<Remove this before reply> wrote in
message news:u2******** ******@TK2MSFTN GP09.phx.gbl...
Jon,

Thanks for the quick reply. I kind of suspected that would be the answer
<g>. However, I don't understand (code wise) how to use Invoke to access a
property. I understand how to use it for accessing a method. Do you just
treat the property of interest as if it's a method that has no arguments?
Any example code?

TIA,

John
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
<"John Bowman" <<Remove this before reply> jo*********@the rmo.com>>
wrote:
I've read "Cybertof"' s thread (04/19/04) & the article he provided in a
link
about accessing UI elements from a thread that did not create them.
What
the authors are saying makes plenty of sense. However, using the control's
Invoke method handles calling it's methods, but what about accessing

the control's properties from another thread? What's the proper way to do

that?

Again, through a delegate and Invoke. You shouldn't access the property
directly from a non-UI thread.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too


Nov 16 '05 #5
Jon & Stoitcho,

Thanks for the help. I should be able to continue from here.

John
"Stoitcho Goutsev (100) [C# MVP]" <10*@100.com> wrote in message
news:ux******** ******@tk2msftn gp13.phx.gbl...
Hi John,

You can use a method to access a property. This would be a special method
that you call thru Invoke and this method sets or gets the property. The
other way is to create a delegate to invoke the 'get' or 'set' accessor of
the property directly. Hoewever IMHO the first is more easy to use. For
invoking the accessor directly you can follow this link
http://groups.google.ca/groups?hl=en...sor%2Bstoitcho Look for my post, which is last in the thread.
--
HTH
B\rgds
Stoitcho Goutsev (100) [C# MVP]

"John Bowman jo*********@the rmo.com>" <<Remove this before reply> wrote in
message news:u2******** ******@TK2MSFTN GP09.phx.gbl...
Jon,

Thanks for the quick reply. I kind of suspected that would be the answer
<g>. However, I don't understand (code wise) how to use Invoke to access a
property. I understand how to use it for accessing a method. Do you just
treat the property of interest as if it's a method that has no arguments? Any example code?

TIA,

John
"Jon Skeet [C# MVP]" <sk***@pobox.co m> wrote in message
news:MP******** *************** *@msnews.micros oft.com...
<"John Bowman" <<Remove this before reply> jo*********@the rmo.com>>
wrote:
> I've read "Cybertof"' s thread (04/19/04) & the article he provided in
a
link
> about accessing UI elements from a thread that did not create them. What
the
> authors are saying makes plenty of sense. However, using the

control's > Invoke method handles calling it's methods, but what about accessing

the > control's properties from another thread? What's the proper way to do that?

Again, through a delegate and Invoke. You shouldn't access the

property directly from a non-UI thread.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too



Nov 16 '05 #6

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

Similar topics

1
3544
by: Bernerd | last post by:
Would anyone out there tell me how to make my C# datagrid wrap the text in the cells. I haven't seen a good how to out there that does this. I know it has something to do with using styles but haven't got styles to work right yet with my grid that get's dynamically populated by xml files. Here's my code that gets the grid. private void mnuContacts_Click(object sender, System.EventArgs e) {
4
2208
by: cybertof | last post by:
Hello, I have read the following article : "You cannot interact with UI elements from a thread that did not create them." The article comes from http://www.codeproject.com/csharp/winformsthreading.asp
13
1680
by: Jeff Davis | last post by:
Right now performance isn't a problem, but this question has me curious: Let's say I have a shopping cart system where there is a "products" table that contains all possible products, and an "cart_items" table that stores how many of each product are in each cart. The obvious (or the first thing that came to my mind) would look something like this: create table products (
19
8388
by: Steve | last post by:
ASP error number 13 - Type mismatch with SELECT...FOR UPDATE statement I got ASP error number 13 when I use the SELECT...FOR UPDATE statement as below. However, if I use SELECT statement without FOR UPDATE, it is fine and no error. I also tried Set objRs = objConn.Execute("SELECT * FROM EMP UPDATE OF EMPNO"), but it still couldn't help. any ideas? I tried to search in the web but couldn't find similar
0
1280
by: hbomb | last post by:
I have a form which is used to both enter data for an application and to view a snapshot of previous data entered for students. The database’s initial point of entry is a form called INTERESTED (whose row source is a table with the same name), for students that simply express an interest in studying abroad. The data from that table is then related to another table which has application information once the students begin the application process....
0
1061
by: bacjoe | last post by:
I am new to writing multi-threaded code and am working on a Windows forms MDI application. There is an MDI Form that can have 0 to many MDI Children. The MDI form starts a thread that is used to poll a device via a USB port. When new data is available from the device, the thread raises an event that the child forms can subscribe to. The event handlers in the child forms update themselves based on the new data that has arrived from the...
1
3147
by: giovannino | last post by:
Dear all, I did a query which update a sequence number (column NR_SEQUENZA) in a table using a nice code (from Trevor !). 1) Given that I'm not a programmer I can't understand why numbering doesn't start always, running more times the update query, from the same starting parameter assigned (1000000000). It seems to me that it takes memory last number calculated and running prox update it starts from last table row updated. I need...
3
3376
by: grinder332518 | last post by:
My Form accesses a Query as follows : SELECT tblA.A, tblB.B, tblB.C FROM tblA LEFT JOIN tblB ON tblA.A = tblB.A UNION SELECT tblB.A, tblB.B, tblB.C FROM tblB LEFT JOIN TblA ON tblB.A = TblA.A WHERE tblB.A not in (select TblA.A from TblA) This gives me all the rows from tblA, with tblB columns B & C, when present,
10
46413
NeoPa
by: NeoPa | last post by:
Introduction. A very common question we have here on Bytes relates to how bound forms update the record data automatically when the focus is in any way moved away from the current record onto another, or new, record. In many instances this is required behaviour. It can make a form work similarly to reviewing data in a table grid. Sometimes however, the designer feels that the users may make changes to the data stick (save them away)...
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10398
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10133
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7669
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.