Solved

Background Worker

Posted on 2011-02-22
5
388 Views
Last Modified: 2012-05-11
Hi,

After reading several articles it appears that it is not possible to reference UI controls from the DoWork event on the BackgroundWorker control.

I need to retrieve some control values in the DoWork event to run a sql query.
e.g string controlValue = combobo.SelectedItem.ToString();

Is there anyway this can be done?

Thanks
0
Comment
Question by:dwhitfield_CPWN
  • 2
  • 2
5 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 34950478
You pass them as a parameter into the worker thread when you start it.
0
 

Author Comment

by:dwhitfield_CPWN
ID: 34950504
do you mean backgroundWorker1.RunWorkerAsync(combobox.SelectedItem.ToString());?
0
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 500 total points
ID: 34950526
That sort of idea - yes.

If you have more than one parameter then make a new class/structure and pass that into the worker
0
 
LVL 12

Expert Comment

by:Wouter Boevink
ID: 34950562
It's possible but you'll have to use delegates.

Look at this sample:

http://www.codeproject.com/KB/threads/ThreadCallBack.aspx?msg=2876487
0
 

Author Closing Comment

by:dwhitfield_CPWN
ID: 34950743
Thanks that worked.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now