Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Background Worker

Posted on 2011-02-22
5
Medium Priority
?
395 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

722 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