Link to home
Start Free TrialLog in
Avatar of RockBaby
RockBabyFlag for Singapore

asked on

Progress Box

Hi,
I need to creating something like a progress box. From my app, when i click save in the SDialog, how can i do something like once i click OK, there will be a Progress Box appear but at the backend, it's saving my document.


SaveFileDialog SDialog = new SaveFileDialog();
SDialog.Filter = "Text Files(*.csv)|*.csv";

if (SDialog.ShowDialog() == DialogResult.OK)
{
   frmExecutingRpt frm=new frmExecutingRpt(this);
   frm.ShowDialog();
   //The progress Box will be appear here but the following code still running..

   using (StreamWriter FWriter = new StreamWriter(SDialog.FileName))
   {
      FWriter.WriteLine(DateTime.Now + "\n");
      FWriter.WriteLine(",,,,Events Report\n");
      FWriter.WriteLine("Alarm Time, Alarm, License No, TID, Latitude, Longitude, POLCOM(Ack),"
      +"COSCOM(Ack), POCC(Ack)");

         foreach (DataRow datarow2 in streamTable.Rows)
         {
            FWriter.WriteLine(datarow2["license_n"]);

               foreach (DataRow datarow in streamTable.Rows)
      {
            FWriter.WriteLine(datarow["alarmtime_dt"] + "," + datarow["des_x"] + "," + datarow
                           "license_n"] + "," + datarow["transid_c"] + ","  + datarow["lat_n"] + "," + datarow["lon_n"]
                          + "," + datarow["pcgack_i"] + ","  + datarow["rsnack_i"] + "," + datarow["pocc1ack_i"]);
      }
            }
FWriter.Close();
frm.Close();
//The progress box will be close here...
           Invoke( new ReportGenerationCompleteDelegate( OnReportCompleted ) );
    }
}
ASKER CERTIFIED SOLUTION
Avatar of Gautham Janardhan
Gautham Janardhan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jasonclarke
jasonclarke

This article at MSDN by Chris Sells is about doing background processing safely in Windows - but it does contain a fairly good worked example that demonstrates what you are trying to do:

http://msdn2.microsoft.com/en-us/library/ms951089.aspx
Avatar of RockBaby

ASKER

when i tried tat method, the new frame did appear but it seems hang there.. but my code is still running..
In order to get the progress bar running properly you need to run the code on a worker thread.

Are you using .NET 2.0?  Take a look at the BackgroundWorker class if you are.
can i have another thread running in a thread?
s u can
BackgroundWorker is a simple way of doing it..
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial