473,385 Members | 1,645 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.

Accessing UI components on a background thread.

Hello,

I know that it's a bad thing to update UI components on a background
thread. But is it fairly safe to access them? I want to iterate
through a tree list.

Thanks.
Sep 24 '07 #1
4 1440
Frank,

The only methods on a class that derives from Control that are safe to
invoke from any thread are Invoke, BeginInvoke, EndInvoke and CreateGraphics
(if the handle for the control has already been created). Other than that,
anything to access a property/method on the UI has to be called on the UI
thread, through the Invoke method if from another thread (which will marshal
the call to the UI thread).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frank Rizzo" <no**@none.comwrote in message
news:ez**************@TK2MSFTNGP02.phx.gbl...
Hello,

I know that it's a bad thing to update UI components on a background
thread. But is it fairly safe to access them? I want to iterate through
a tree list.

Thanks.

Sep 24 '07 #2
Hi Frank,

Nicholas has provided the best practice rule for you. Actually .Net Winform
controls encapsulate the Win32 native controls. Since the Win32 native
controls are designed as STA COM threading model, we are not allowed to
call it from second thread.

Regarding your task, you may write a helper method which wraps the code to
iterate through your GUI tree list. Then in the second thread, you may use
Control.Invoke or Control.BeginInvoke methods to call this helper method.
This will ensure the thread safety.

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 25 '07 #3
Hi Frank,

Have you reviewed the replies to you? Do they make sense to you? If you
still need any help, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Sep 28 '07 #4
Jeffrey Tan[MSFT] wrote:
Hi Frank,

Have you reviewed the replies to you? Do they make sense to you? If you
still need any help, please feel free to feedback, thanks.
Yes, thank you.
>
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 8 '07 #5

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

Similar topics

3
by: Brenny | last post by:
Hello I'm designing a windows form and form's background image is exist and I added a label and groupbox. There is a spesific image on the form and I want to show this image as label and...
3
by: Alex | last post by:
I'm having a problem porting an ASP solution to ASPX. In the ASP solution I'm accessing a DCOM server, create sub DCOM objects and call functions from VB script on the ASP pages. The DCOM object...
4
by: Martin Hill | last post by:
Hi there, How can I find the components added to web form from my custom web control? Suppose I added a Timer component (with name "timer1") onto the web form, from my user web control, how...
4
by: Luminousc | last post by:
I'm getting my feet wet learning C# and .net from a VBScript background. I have built a small application that uses custom 'info' objects, each of which contains a single record from a SQL...
1
by: JEB | last post by:
I know that with Web Services, you should be doing everything in a stateless environment. However, I have three methods out of over 100 that need state. I have the client cookie container,...
0
by: andycee | last post by:
Hi, I'm working on an app to filter images (by size, EXIF info etc..) and display as a slideshow. To allow the worker thread to continue running whilst performing the longer tasks such as loading...
2
by: Jon Slaughter | last post by:
What concepts do I have to know to access data between two threads safely? Right now I'm using a delegate method and Invoke to call a function in the other thread that handles the data. This...
4
by: Lilith | last post by:
This was easy in C++ (well, relatively.) Now I'm in the C# environment and everything I try doesn't work. I'm running a thread in which I have two accesses I need to components on a form. In...
2
by: DevInCode | last post by:
I'm looking for some help or suggestions about something I'm working on. I'm using the webbrowser control in VB.net. I want to click a button and have the webbrowser go to a certain website...
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
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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.