tags:

views:

101

answers:

2

Hi, I have a function in a class: for each fetched record in this function I write the record to a file, I also want to add the value/count of this fetched record in my progressbar, BUT this progressbar exists in the form page and the function exists in my class, I call the function in the formpage

here is a part of this function

        this.path_to_file =
        ConfigurationManager.AppSettings["ExportDir"] +
DateTime.Now.ToString(ConfigurationManager.AppSettings
["Export_FileName"]) + ConfigurationManager.AppSettings
["Export_Extension"];


        FileStream fm = new FileStream
           (this.path_to_file, FileMode.Create, FileAccess.ReadWrite,
FileShare.ReadWrite);

        StreamWriter sw = new StreamWriter(fm, Encoding.Default);

        List<Export> exportRecords = null;

        exportRecords = ExportList();
        try
        {
            int i = 0;
           foreach (Export ex in exportRecords)
           {
               sw.Write(ex.ExportLine());
              sw.Write(sw.NewLine);
              sw.Flush();
               i++;
           }
        }
        catch (Exception exc)
        {
           Log.Write(exc.Message);
        }

it returns strings

+1  A: 

Have your class raise an event with the progress, and your form update accordingly.

Or better yet, do it on a background thread:

http://msdn.microsoft.com/en-us/library/system.componentmodel.backgroundworker.aspx

Stu
A: 

could you give me an example of how i can do that

Sjemmie
Were you talking to me? Do you mean an example of how to raise such an event?
Stu