F
Fir5tSight
Hi all,
I have a working C#.NET program. It looks like the follows:
FormMain.cs:
private void buttonCompare_Click(object sender, EventArgs e)
{
foreach (FileName f in allPaceFiles)
{
CompareOnePairOfFiles(f, iCompareType, tol, sw, txtOutput,
FilesProcessed, FilesPassed, FilesFailed);
}
}
private void CompareOnePairOfFiles(FileName f, int iCompareType,
Tolerance tol,
StreamWriter sw, string
txtOutput,
int FilesProcessed, int
FilesPassed, int FilesFailed)
{
// blah blah blah
}
Now I want to improve it to use multiple (two) threads to increase the
speed. Therefore, it looks like the follows:
FormMain.cs:
private void buttonCompare_Click(object sender, EventArgs e)
{
foreach (FileName f in allPaceFiles)
{
Checker checker1 = new Checker(f, iCompareType, tol,
sw, txtOutput, FilesProcessed, FilesPassed, FilesFailed);
checker1.Start();
Checker checker2 = new Checker(f, iCompareType, tol,
sw, txtOutput, FilesProcessed, FilesPassed, FilesFailed);
checker2.Start();
}
}
private void CompareOnePairOfFiles(FileName f, int iCompareType,
Tolerance tol,
StreamWriter sw, string
txtOutput,
int FilesProcessed, int
FilesPassed, int FilesFailed)
{
// blah blah blah
}
Checker.cs:
public class Checker
{
Checker(FileName f, int iCompareType, Tolerance tol,
StreamWriter sw, string txtOutput,
int FilesProcessed, int FilesPassed, int
FilesFailed)
{
// assign these values to members of Checker
}
protected BackgroundWorker worker;
public void Start()
{
if (worker == null)
{
worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(DoWork);
}
if (worker == null)
{
return;
}
}
protected virtual void DoWork(object sender, DoWorkEventArgs e)
{
try
{
// Compare one pair of reports
CompareOnePairOfFiles(f, iCompareType, tol, sw,
txtOutput, FilesProcessed, FilesPassed, FilesFailed);
}
catch (Exception exc)
{
// message
}
}
I get two compiling errors:
1) The name 'CompareOnePairOfFiles' not exist in the current context.
2) 'new Checker(...)' is inaccessible due to its protection level
It seems that there is a flaw in my design. Will anyone advise me on
how to make it work?
Thanks!
-Emily
I have a working C#.NET program. It looks like the follows:
FormMain.cs:
private void buttonCompare_Click(object sender, EventArgs e)
{
foreach (FileName f in allPaceFiles)
{
CompareOnePairOfFiles(f, iCompareType, tol, sw, txtOutput,
FilesProcessed, FilesPassed, FilesFailed);
}
}
private void CompareOnePairOfFiles(FileName f, int iCompareType,
Tolerance tol,
StreamWriter sw, string
txtOutput,
int FilesProcessed, int
FilesPassed, int FilesFailed)
{
// blah blah blah
}
Now I want to improve it to use multiple (two) threads to increase the
speed. Therefore, it looks like the follows:
FormMain.cs:
private void buttonCompare_Click(object sender, EventArgs e)
{
foreach (FileName f in allPaceFiles)
{
Checker checker1 = new Checker(f, iCompareType, tol,
sw, txtOutput, FilesProcessed, FilesPassed, FilesFailed);
checker1.Start();
Checker checker2 = new Checker(f, iCompareType, tol,
sw, txtOutput, FilesProcessed, FilesPassed, FilesFailed);
checker2.Start();
}
}
private void CompareOnePairOfFiles(FileName f, int iCompareType,
Tolerance tol,
StreamWriter sw, string
txtOutput,
int FilesProcessed, int
FilesPassed, int FilesFailed)
{
// blah blah blah
}
Checker.cs:
public class Checker
{
Checker(FileName f, int iCompareType, Tolerance tol,
StreamWriter sw, string txtOutput,
int FilesProcessed, int FilesPassed, int
FilesFailed)
{
// assign these values to members of Checker
}
protected BackgroundWorker worker;
public void Start()
{
if (worker == null)
{
worker = new BackgroundWorker();
worker.DoWork += new DoWorkEventHandler(DoWork);
}
if (worker == null)
{
return;
}
}
protected virtual void DoWork(object sender, DoWorkEventArgs e)
{
try
{
// Compare one pair of reports
CompareOnePairOfFiles(f, iCompareType, tol, sw,
txtOutput, FilesProcessed, FilesPassed, FilesFailed);
}
catch (Exception exc)
{
// message
}
}
I get two compiling errors:
1) The name 'CompareOnePairOfFiles' not exist in the current context.
2) 'new Checker(...)' is inaccessible due to its protection level
It seems that there is a flaw in my design. Will anyone advise me on
how to make it work?
Thanks!
-Emily