Solved

Background Worker

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
The Using statement in C# 5 36
Build JSON from table records 17 40
asp.net mvc5 3 38
optimize  c# code 7 48
Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

18 Experts available now in Live!

Get 1:1 Help Now