Solved

Background Worker

Posted on 2011-02-22
5
392 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…

738 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