Hi Miha, thanks for the reply. Yes I am using threading. I've tried to
base my code off of this
http://msdn.microsoft.com/library/de...ms06112002.asp
This is my first attempt at using threading so I may be doing
something wrong. Everything seems to work perfect until I get a lot of
data. The most rows I've added is several hundred, I'm not sure of an
exact number. I haven't done anything with the a Cancel button, but
some of that code is left in. My threading code is posted below. Any
suggestions are much appreciated. Thanks
Progress p = new Progress();
p.popData(shown Vals, numArticles);
public class Progress : System.Windows. Forms.Form
{
public Progress()
{}
enum CalcState
{
Pending,
Calculating,
Canceled,
}
Form1 f=(Form1)Update MyWay.Form1.Act iveForm;
CalcState state = CalcState.Pendi ng;
class ShowProgressArg s : EventArgs
{
public string[] progressArr;
public bool Cancel;
public string numArticles;
public ShowProgressArg s(string[] progressArr,
string numArticles)
{
this.numArticle s = numArticles;
this.progressAr r = progressArr;
}
}
delegate void ShowProgressHan dler(object sender, ShowProgressArg s e);
void ShowProgress(ob ject sender, ShowProgressArg s e)
{
// Make sure we're on the right thread
if( this.InvokeRequ ired == false )
{
// Check for Cancel
e.Cancel = (state == CalcState.Cance led);
Convert.ToBoole an(e.progressAr r[0]);
f.textBox1.Text = e.numArticles;
f.textBox1.Upda te();
f.data.Rows.Add (e.progressArr) ;
f.myDataGrid.Up date();
// Check for completion
if( e.Cancel)
{
state = CalcState.Pendi ng;
}
}
// Transfer control to correct thread
else
{
ShowProgressHan dler
showProgress = new ShowProgressHan dler(ShowProgre ss);
Invoke(showProg ress, new object[] { sender, e});
}
}
public void popData(string[] sData, string nArticles)
{
object sender = System.Threadin g.Thread.Curren tThread;
ShowProgressArg s e = new ShowProgressArg s(sData, nArticles);
// Show progress (ignoring Cancel so soon)
ShowProgress(se nder, e);
}
}
//Thanks Miha ;)
On Sun, 22 Feb 2004 11:31:09 +0100, "Miha Markic [MVP C#]" <miha at
rthand com> wrote:
Hi,
Are you using threading by any chance?