thanks. i'm sorry if i'm not using the right terms.
i will try to be clearer as i try to explain my issues. i'm suppling a mock
up of my program. i put ":" in place where there is code not related to my
BackgroundWorker.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using Microsoft.VisualBasic;
using System.Threading;
namespace CallFlow
{
public partial class fCallFlow : Form
{
public fCallFlow()
{
InitializeComponent();
InitializeBackgroudWorker();
}
private void InitializeBackgroudWorker()
{
bgWorker.DoWork += new
System.ComponentModel.DoWorkEventHandler(this.bgWorker_DoWork);
//bgWorker.ProgressChanged += new
ProgressChangedEventHandler(bgWorker_ProgressChanged);
bgWorker.RunWorkerCompleted += new
RunWorkerCompletedEventHandler(bgWorker_RunWorkerCompleted);
}
private bool parseuserlog(string filename, string sfilename)
{
:
:
:
//do some work
// update the windows form giving status to the user
tbStatus.Text = "Reading the input file. Creating temp
files.\r\n";
:
//the code for heavy processing
:
:
}//private bool parseuserlog(string filename)
private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
runProgram((string)e.Argument, worker, e);
}//private void bgWorker_DoWork(object sender, DoWorkEventArgs e)
private void bgWorker_RunWorkerCompleted(object sender,
RunWorkerCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message);
}
else if (e.Cancelled)
{
MessageBox.Show("Canceled");
this.bgWorker.CancelAsync();
}
else
{
MessageBox.Show("Done");
}
}//private void bgWorker_RunWorkerCompleted(oject sender,
RunWorkerCompletedEventArgs e)
private void bgWorker_ProgressChangeed(object sender,
ProgressChangedEventArgs e)
{
//e.UserState
//ProgressChangedEventArgs.UserState property
}
private void runProgram(string filename, BackgroundWorker worker,
DoWorkEventArgs e)
{
:
//check the windows form to see if a user option is set
if (cbTraces.Checked == true)
bTrace = true;
:
//get the file name to append to the output files.
sfilename = fileChoice.SafeFileName.Substring(0,
fileChoice.SafeFileName.IndexOf("."));
if (worker.CancellationPending)
{
e.Cancel = true;
}
//call the code that does the heavy process
if (!parseuserlog(filename, sfilename))
{
MessageBox.Show("Error in parseuserlog function.");
Application.Exit();
}
:
//provide a status to the window form
tbStatus.Text += "Starting to process the PHHONEMAIL script
data.\r\n";
tbStatus.Refresh();
if (worker.CancellationPending)
{
e.Cancel = true;
}
//code to call another heavy task
if (!parsephonemaildata2(sfilename))
MessageBox.Show("Error");
:
//provide a status to the window form
tbStatus.Text += "Starting to process the Vogue script data.\r\n";
tbStatus.Refresh();
//code to call another heavy task
if (!parsevoguedata2(sfilename))
{
MessageBox.Show("Error in parsevoguedata function.");
Application.Exit();
}
//provide status to the window form
tbStatus.Text += "Starting to process data AVERAGES.\r\n";
tbStatus.Refresh();
if (worker.CancellationPending)
{
e.Cancel = true;
}
//code to call another heavy task
getAverages(sfilename);
}//private void runProgram(string useless, BackgroundWorker worker,
DoWorkEventArgs e)
private void bProcess_Click(object sender, EventArgs e)
{
:
:
//code that starts when the user selects a window form button
:
//start the background thread
bgWorker.RunWorkerAsync(filename);
:
}//private void bProcess_Click(object sender, EventArgs e)
private bool parsephonemaildata2(string sfilename)
{
:
//heavy code task with no status to the window form
:
return (true);
}//private bool parsephonemaildata2()
private bool parsevoguedata2(string sfilename)
{
:
//code for heavy task.
//status to update windows form
tbStatus.Text += "Number of lines ran in VOGUE script: " +
lSessionID.ToString() + "\r\n";
:
return (true);
}//private bool parsevoguedata2()
private void fCallFlow_Load(object sender, EventArgs e)
{
tbVersion.Text = "Version 2.2";
}//private long convertsession(string sSession)
private void bCancel_Click(object sender, EventArgs e)
{
Application.Exit();
}
}//public partial class fCallFlow : Form
}//namespace CallFlow
the windows form "command" button calls "private void bProcess_click(object
sender, EventArgs e)" which when invoked calls the function "private void
runProgram( string useless, BackgroundWorker worker, DoWorkEventArgs e)".
this inturns fires off the worker thread that calls 3 heavy process
functions.
one such function "private bool parseuser(string filename, string
sfilename)" does a heavy number crunching task and has to give an update to
the windows form not to a progress bar but to TextBox which i want to give
verbal updates.
the first issue i have is that i'm not sure if the "worker" object can be
passed down to this function? if so what is the method for this?
i guess if i can do that i can figure it out for the other functions called
by the "runProgram" function that controls the thread. (i'm sorry if still
get the terms wrong).
the sample i found talk about simple process to the progress bar and only 1
level. they don't outline how to update labels, textboxes, and statusbars.
thanks for any help.