English 中文(简体)
Howto trigger Progressbar from a function in the data access layer
原标题:

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

问题回答

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





相关问题
WPF Progressbar continue animation

I m using the progress bar of WPF and set the value until the max value. But, when reached, the animation (that s the green effect) continues. How can I stop it and have a full filled green bar, ...

Progress messages - user experience

When displaying progress bars do you display generic messages, such as: "Working" "Loading" "In Progress" Or is the additional coding effort worth the user experience improvements resulting from ...

Adobe Flex Progress Bar for LoadStyleDeclarations

I m loading a rather large swf as style with the following command: StyleManager.loadStyleDeclarations("assets/modules/"style.swf",true,false,ApplicationDomain.currentDomain); The style is loaded ...

Multiline progress bars

I know that to update something like a progress bar on the command line, one uses . Is there any way to update multiple lines?

Flex HTTPService Progressbar

How can I set a progress bar that may start when an HTTPService is sent and stop when the HTTPService ends? I followed code given here but encountered following error: Type was not found or was ...

Display progress bar in the program s task bar icon

I was seeing that when you do somethings at Windows 7 that haves a progress bar, things like downloading a file. You can see that in the programs bar, at the icon of the application, there is the ...

热门标签