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/default.asp?url=/library/en-us/dnforms/html/winforms06112002.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(shownVals, numArticles);
public class Progress : System.Windows.Forms.Form
{
public Progress()
{}
enum CalcState
{
Pending,
Calculating,
Canceled,
}
Form1 f=(Form1)UpdateMyWay.Form1.ActiveForm;
CalcState state = CalcState.Pending;
class ShowProgressArgs : EventArgs
{
public string[] progressArr;
public bool Cancel;
public string numArticles;
public ShowProgressArgs(string[] progressArr,
string numArticles)
{
this.numArticles = numArticles;
this.progressArr = progressArr;
}
}
delegate void ShowProgressHandler(object sender, ShowProgressArgs e);
void ShowProgress(object sender, ShowProgressArgs e)
{
// Make sure we're on the right thread
if( this.InvokeRequired == false )
{
// Check for Cancel
e.Cancel = (state == CalcState.Canceled);
Convert.ToBoolean(e.progressArr[0]);
f.textBox1.Text= e.numArticles;
f.textBox1.Update();
f.data.Rows.Add(e.progressArr);
f.myDataGrid.Update();
// Check for completion
if( e.Cancel)
{
state = CalcState.Pending;
}
}
// Transfer control to correct thread
else
{
ShowProgressHandler
showProgress = new ShowProgressHandler(ShowProgress);
Invoke(showProgress, new object[] { sender, e});
}
}
public void popData(string[] sData, string nArticles)
{
object sender = System.Threading.Thread.CurrentThread;
ShowProgressArgs e = new ShowProgressArgs(sData, nArticles);
// Show progress (ignoring Cancel so soon)
ShowProgress(sender, e);
}
}
//Thanks Miha
Hi,
Are you using threading by any chance?