Click here to Skip to main content
15,891,017 members
Home / Discussions / C#
   

C#

 
AnswerRe: thread safe calls Pin
kasik2-Feb-06 9:35
kasik2-Feb-06 9:35 
GeneralRe: thread safe calls Pin
eligazit2-Feb-06 10:50
eligazit2-Feb-06 10:50 
GeneralRe: thread safe calls Pin
kasik2-Feb-06 11:01
kasik2-Feb-06 11:01 
GeneralRe: thread safe calls Pin
kasik2-Feb-06 11:19
kasik2-Feb-06 11:19 
GeneralRe: thread safe calls Pin
Dave Kreskowiak2-Feb-06 15:29
mveDave Kreskowiak2-Feb-06 15:29 
GeneralRe: thread safe calls Pin
kasik3-Feb-06 2:26
kasik3-Feb-06 2:26 
GeneralRe: thread safe calls Pin
Dave Kreskowiak3-Feb-06 3:07
mveDave Kreskowiak3-Feb-06 3:07 
GeneralRe: thread safe calls Pin
eligazit2-Feb-06 20:42
eligazit2-Feb-06 20:42 
To update GUI with the BackgroundWorker, you need to do the following steps:
1. When creating the wroker:
public void InitWorker()
{
worker = new BackgroundWorker();
worker.WorkerReportsProgress = true;
worker.ProgressChanged += new ProgressChangedEventHandler(worker_ProgressChanged);
worker.DoWork += new DoWorkEventHandler(worker_DoWork);
}
Note that I've creating new event handler to update GUI, when ever I want to set something on the GUI, I should call the ReportProgress(...) method of the worker:

void worker_DoWork(object sender, DoWorkEventArgs e)
{

// Some long operation
// .....
Thread.Sleep(2000);
// Update GUI
worker.ReportProgress(30);
// Some long operation
// .....
Thread.Sleep(2000);
// Update GUI
worker.ReportProgress(60);
// Some long operation
// .....
Thread.Sleep(2000);
// Update GUI
worker.ReportProgress(90);


}

And, on the ReportProgress handler, I can update the GUI as I want, this is beacuse the worker handles moving the OS the the right thread so it is not my problem...

void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
Label label;
label.Text = e.ProgressPercentage + "%";
}

Note that on the ReportProgress you can send an object that will be set on the ProgressChangedEventArgs (State), in this property you can set all the values you want to update on the GUI (other than the precentage).

GeneralRe: thread safe calls Pin
kasik3-Feb-06 2:32
kasik3-Feb-06 2:32 
Questiontransferring vb.net solution to c#.net Pin
kourvoisier2-Feb-06 8:34
kourvoisier2-Feb-06 8:34 
AnswerRe: transferring vb.net solution to c#.net Pin
malharone2-Feb-06 11:19
malharone2-Feb-06 11:19 
GeneralRe: transferring vb.net solution to c#.net Pin
kourvoisier2-Feb-06 11:20
kourvoisier2-Feb-06 11:20 
GeneralRe: transferring vb.net solution to c#.net Pin
malharone2-Feb-06 11:41
malharone2-Feb-06 11:41 
Questioncreating a truly transparent control Pin
melanieab2-Feb-06 7:58
melanieab2-Feb-06 7:58 
QuestionRe: creating a truly transparent control Pin
melanieab2-Feb-06 8:34
melanieab2-Feb-06 8:34 
AnswerRe: creating a truly transparent control Pin
microsoc2-Feb-06 21:15
microsoc2-Feb-06 21:15 
QuestionInserting a record and retrieving recordid Pin
moazzamahmed2-Feb-06 7:00
moazzamahmed2-Feb-06 7:00 
AnswerRe: Inserting a record and retrieving recordid Pin
Colin Angus Mackay2-Feb-06 7:25
Colin Angus Mackay2-Feb-06 7:25 
AnswerRe: Inserting a record and retrieving recordid Pin
malharone2-Feb-06 7:33
malharone2-Feb-06 7:33 
QuestionSystem Bitmaps Pin
deepscyberpulse2-Feb-06 6:26
deepscyberpulse2-Feb-06 6:26 
AnswerRe: System Bitmaps Pin
malharone2-Feb-06 6:31
malharone2-Feb-06 6:31 
AnswerRe: System Bitmaps Pin
James Gupta2-Feb-06 8:30
professionalJames Gupta2-Feb-06 8:30 
QuestionProblems with VB 6.0 App loading .net assembly with own mdi window (message loop)... Pin
Chris Richner2-Feb-06 6:26
Chris Richner2-Feb-06 6:26 
QuestionSorting? algorithm Pin
criz84262-Feb-06 6:17
criz84262-Feb-06 6:17 
AnswerRe: Sorting? algorithm Pin
Paddy Boyd2-Feb-06 6:26
Paddy Boyd2-Feb-06 6:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.