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

c# winforms control threading

I have an application that loads many controls and data on startup. This takes a little while so I decided to implement a progress bar. Idealy i would use a backgroundworker to perform the work and report progress, but controls I create in this thread will not be usable on the host form due to being created on a different thread. This raises two questions:

1: why are controls locked to the thread they were created on?. and

2: how could i transfer ownership from the background thread to the main application thread?
Oct 28 '08 #1
1 1679
tlhintoq
3,525 Expert 2GB
I have an application that loads many controls and data on startup. This takes a little while so I decided to implement a progress bar. Idealy i would use a backgroundworker to perform the work and report progress, but controls I create in this thread will not be usable on the host form due to being created on a different thread. This raises two questions:

1: why are controls locked to the thread they were created on?. and

2: how could i transfer ownership from the background thread to the main application thread?
Try just using the background thread for a small ShowProgress class that includes the progress bar control. Don't include the making of anything in that thread. Its only purpose is to show the progress status.

Use an event in your control creation thread that occurs when something significant happens (like 10 more controls are added)

Have the progress bar class/thread subscribe to the the custom event. So when ever the event fires, the progress bar will update/step.

Of course you'll have to give it a couple properties like Minimum and Maximum so it can calculate how much is left etc.
Oct 29 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

10
by: J.Marsch | last post by:
I know that the controls on a Winform are not thread safe, and that you want to do all of your UI updates on a single thread -- generally the main thread. Now, 2 questions: 1. Does the one...
10
by: BBFrost | last post by:
We just recently moved one of our major c# apps from VS Net 2002 to VS Net 2003. At first things were looking ok, now problems are starting to appear. So far ... (1) ...
4
by: Elhanan | last post by:
hi.. all a client of ours is considering to move from a dos application to windows desktop application. the application is for traveling agency, the database is rather large. their current...
3
by: GroZZleR | last post by:
Hey all, I'm threading newbie, I've never attempted it before. I've got a button that when clicked starts up a thread to process some files. This keeps my GUI responsive and gets the tasks...
5
by: Segfahlt | last post by:
I need a little help here please. I have 2 win forms user controls in 2 different projects that I'm hosting in 2 different virtual directories. The controls have been test and operate okay in...
17
by: nicolas.hilaire | last post by:
Hi all, i'm doing a quite long treatment in a function, and i'm showing the progress of the treatment with a progressbar. The code is something like this : for each(entry in entries) // about...
5
by: brian.wilson4 | last post by:
Our group is currently comparing winforms vs webforms.....app is Corp LAN based - we have control of desktops.....Below is pros and cons list we have come up with - if anything strikes you as...
3
by: D. Patrick | last post by:
I need to guide the training for some good ASP.NET programmers who don't have Windows Forms experience, and they will soon be put onto a project for multi-threaded winforms development. Can...
5
by: Peted | last post by:
Just some threading questions 1. in a MDI app if you have multiple child forms, does each child form run in its own thread ? Eg do you get error trying to update one control on form1 from...
2
by: =?Utf-8?B?TWljaGFlbCBXLg==?= | last post by:
Dear ng, i have developed a winforms application with vs2005. An progress from with a animation and a timer is shown while the application is working. The trouble is, that often a...
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: 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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...

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.