473,385 Members | 1,742 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,385 software developers and data experts.

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*********@thermo.com
Nov 16 '05 #1
5 1401
<"John Bowman" <<Remove this before reply> jo*********@thermo.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.com>
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.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"John Bowman" <<Remove this before reply> jo*********@thermo.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.com>
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*********@thermo.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 StringReturningDelegate();

string GetLabelText()
{
return label.Text;
}

....

myControl.Invoke
(new StringReturningDelegate(myControl.GetLabelText());

should work.

--
Jon Skeet - <sk***@pobox.com>
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*********@thermo.com>" <<Remove this before reply> wrote in
message news:u2**************@TK2MSFTNGP09.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.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"John Bowman" <<Remove this before reply> jo*********@thermo.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.com>
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**************@tk2msftngp13.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*********@thermo.com>" <<Remove this before reply> wrote in
message news:u2**************@TK2MSFTNGP09.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.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<"John Bowman" <<Remove this before reply> jo*********@thermo.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.com>
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
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...
4
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...
13
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...
19
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...
0
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...
0
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...
1
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...
3
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 ...
10
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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: 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:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.