G
Guest
I want to create an app in VS 2003 (not in 2005 !!).
It works this way: user chooses an excel file in openfiledialog. then he
clicks OK and a new form appears. There is a progressbar on the form. It
shows progress of reading the file. In the form I put FormLoad event:
System.Threading.Thread thr=new System.Threading.Thread(Read);
thr.Start();
and Read() function:
void Read()
{
while(/*read next row in the file*/)
{
/*insert the row into a database*/
/*...........*/
progressbar1.Increment(1);
}
}
it seems to work ok. But no-one has taught me how to use threads,. Is it a
good way? I am a newbie... I dont use any Invoke/BeginInvoke methods. Should
I?
The problem is that sometimes the app works fine, sometimes not.
Sometimes all of the rpows from the file are read and inserted to the db but
so,etimes only a few of them and the app freezes. Why?
There is also red cross on the form which closes the form. What is the best
way to handle the event when user clicks it? I mean when user clicks it, a
messegebox should apper "Stop the reading process?" Yes/No.
I did it this way. Whe user clicks Yes i call thr.Abort(). It works ok - the
app stops working but after a while I am getting message: The thread wa being
stopped? How to avoid that?
thx in advance
It works this way: user chooses an excel file in openfiledialog. then he
clicks OK and a new form appears. There is a progressbar on the form. It
shows progress of reading the file. In the form I put FormLoad event:
System.Threading.Thread thr=new System.Threading.Thread(Read);
thr.Start();
and Read() function:
void Read()
{
while(/*read next row in the file*/)
{
/*insert the row into a database*/
/*...........*/
progressbar1.Increment(1);
}
}
it seems to work ok. But no-one has taught me how to use threads,. Is it a
good way? I am a newbie... I dont use any Invoke/BeginInvoke methods. Should
I?
The problem is that sometimes the app works fine, sometimes not.
Sometimes all of the rpows from the file are read and inserted to the db but
so,etimes only a few of them and the app freezes. Why?
There is also red cross on the form which closes the form. What is the best
way to handle the event when user clicks it? I mean when user clicks it, a
messegebox should apper "Stop the reading process?" Yes/No.
I did it this way. Whe user clicks Yes i call thr.Abort(). It works ok - the
app stops working but after a while I am getting message: The thread wa being
stopped? How to avoid that?
thx in advance