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 ) );
    }
}
C#Programming Languages-Other

Avatar of undefined
Last Comment
jasonclarke
ASKER CERTIFIED SOLUTION
Avatar of Gautham Janardhan
Gautham Janardhan

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
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
RockBaby
Flag of Singapore image

ASKER

when i tried tat method, the new frame did appear but it seems hang there.. but my code is still running..
Avatar of jasonclarke
jasonclarke

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.
Avatar of RockBaby
RockBaby
Flag of Singapore image

ASKER

can i have another thread running in a thread?
s u can
BackgroundWorker is a simple way of doing it..
SOLUTION
Avatar of jasonclarke
jasonclarke

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
C#
C#

C# is an object-oriented programming language created in conjunction with Microsoft’s .NET framework. Compilation is usually done into the Microsoft Intermediate Language (MSIL), which is then JIT-compiled to native code (and cached) during execution in the Common Language Runtime (CLR).

98K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo