Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

CodeSmith Progress object


May 25, 2021 CodeSmith


Table of contents


The Progress object

Using the Progress object to display a progress bar for codeSmith's code-generating process is useful for generating time-consuming template operations, and if you use Visual Studio, you can display a progress bar in the status bar:

CodeSmith Progress object

The progress bar is used by using the Progress property object of the CodeTemplate object, starting with setting the maximum value and step length of the Progress object, in this case simulating a time-wasted operation with a simple loop:

<%@ Template Language="C#" TargetLanguage="Text" Debug="False" %>

<%@ Import Namespace="System.Threading" %>
This is a progress demo.

<% SimulateProgress(); %>

<script runat="template">
public void SimulateProgress(){

Progress.MaximumValue = 25;
Progress.Step = 1;

    for(int i=0;i<25;i++){
        Progress.PerformStep();
        Thread.Sleep(100);
        Response.WriteLine("step {0} ",i);
    }
}
</script>

Moving the progress bar forward is achieved through the PerfStep method of the Progress object.

This example Downloads