Hi i have a problem can anyone here help me please....
I created a page that basically creates a pdf file. it loops until it reaches the maximum number of file to be generate.
When i click the button that says "Generate PDF" it should disable it self until all the file has been created.
here is how the code flow
Private void Button1_Click(object sender, EventArgs e)
{
Button1.Enabled = False;
for(int i=0 ; i <= max_count ; i++)
{
****** CREATE PDF FILE IN A SPECIFIED FOLDER ******
}
Button1.Enabled = True;
}
*THE PROBLEM
My problem is i notice a delay in creating the pdf files. when my maximum number of loop is set to 30 the loop is over while the created pdf file is only 5 or 7.
The problem is the button is already enabled that time. When i click the button while the files are being created, it will generate another set of pdf files that will cause problems in my application.
So i was hoping that you can help me prevent the button from being enabled until all the files are created no matter how long it took.
Please help...
Loading
Nicholas BrittonPosted Dec 9, 2007, 8:10 AM
Hi
I think the other reply has the key to this problem. Don't put your Button1.Enabled code in this function - put it in the file generator function (assuming it's in the same object) after it's created all the files. There seems to be a threading issue here with the code coming out of the loop before the other function finishes.
Jan MontanoPosted Dec 7, 2007, 5:26 AM
You could just keep track of the files it create and count if all the files are in your specified directory already. And only then you'll enable the generate pdf button.