<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Eclipsed4utoo&#039;s Blog&#187; progressbar</title>
	<atom:link href="http://eclipsed4utoo.com/blog/tag/progressbar/feed/" rel="self" type="application/rss+xml" />
	<link>http://eclipsed4utoo.com/blog</link>
	<description>Not Your Ordinary Programmer</description>
	<lastBuildDate>Thu, 08 Sep 2011 17:09:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>C# &#8211; Windows Form with ProgressBar</title>
		<link>http://eclipsed4utoo.com/blog/windows-form-progressbar/</link>
		<comments>http://eclipsed4utoo.com/blog/windows-form-progressbar/#comments</comments>
		<pubDate>Wed, 09 Sep 2009 18:16:52 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[BackgroundWorker]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[progressbar]]></category>
		<category><![CDATA[windows forms]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=156</guid>
		<description><![CDATA[This post will deal with showing a ProgressBar with a Windows Forms application to show progress of a long process running in the background.  If you have code that will take an abnormal amount of time(more than a few seconds), you don&#8217;t want your UI to &#8220;hang&#8221; because of the long processing.  To get around [...]]]></description>
			<content:encoded><![CDATA[<p>This post will deal with showing a ProgressBar with a Windows Forms application to show progress of a long process running in the background.  If you have code that will take an abnormal amount of time(more than a few seconds), you don&#8217;t want your UI to &#8220;hang&#8221; because of the long processing.  To get around this is to run the long process in a background thread, and update the main UI with progress of where the process is at.</p>
<p>We will be doing this using the BackgroundWorker class.  This is probably the easiest way to get background threads up and running quickly.</p>
<p>So first we will have these using statements at the top.</p>
<pre class="brush: csharp;">
using System;
using System.ComponentModel;
using System.Threading;
using System.Windows.Forms;
</pre>
<p>Next, we define our BackgroundWorker object.</p>
<pre class="brush: csharp;">
BackgroundWorker bgw;

public Form1()
{
    InitializeComponent();
}
</pre>
<p>On my form, I have a button to start the process.  Here is the Click Event for it&#8230;</p>
<pre class="brush: csharp;">
private void btnStart_Click(object sender, EventArgs e)
{
     bgw = new BackgroundWorker();
     bgw.WorkerReportsProgress = true;
     bgw.ProgressChanged += new ProgressChangedEventHandler(bgw_ProgressChanged);
     bgw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bgw_RunWorkerCompleted);
     bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);
     bgw.RunWorkerAsync();
}
</pre>
<p>In the preceding code, we created a new BackgroundWorker object.  We also set the object to allow it to report it&#8217;s progress.  We then create 3 event handlers for the ProgressChanged, RunWorkerCompleted, and DoWork events.  The ProgressChanged event is fired when the progress is changed(like you didn&#8217;t see that one coming).  The RunWorkerCompleted event is fired when the process has been completed.  The DoWork event is the event where your long processing code will go.</p>
<p>The RunWorkerAsync method fires the DoWork event.</p>
<pre class="brush: csharp;">
void bgw_DoWork(object sender, DoWorkEventArgs e)
{
    for (int i = 0; i &lt; 10; i++)
    {
        bgw.ReportProgress((i + 1) * 10);
        Thread.Sleep(1000);
    }
}
</pre>
<p>In the preceding code, I am basically just running a loop that will report the progress of the thread.  It will also stop the thread temporarily so that we can see the progress bar move.</p>
<p>Now I will set the progress bar&#8217;s value to the percentage that I reported.  The progress bar was dragged onto the form from the Toolbox.</p>
<pre class="brush: csharp;">
void bgw_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
    progressBar1.Value = e.ProgressPercentage;
}
</pre>
<p>And last, the code that runs when the task has been completed..</p>
<pre class="brush: csharp;">
void bgw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
     MessageBox.Show(&quot;Finished&quot;);
}
</pre>
<p>And it&#8217;s as simple as that.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/windows-form-progressbar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.Net &#8211; AJAX with Continuous Progress Bar</title>
		<link>http://eclipsed4utoo.com/blog/aspnet-ajax-continuous-progress-bar/</link>
		<comments>http://eclipsed4utoo.com/blog/aspnet-ajax-continuous-progress-bar/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 17:31:16 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Progress Bar]]></category>
		<category><![CDATA[progressbar]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=133</guid>
		<description><![CDATA[I was recently asked about getting a Progress Bar to work in ASP.Net.  It didn&#8217;t need to be a progress bar that had a percentage, just something that would alert a user that something is happening behind the scenes. So I did some Google searching, and found tons of resources where people had created their [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently asked about getting a Progress Bar to work in ASP.Net.  It didn&#8217;t need to be a progress bar that had a percentage, just something that would alert a user that something is happening behind the scenes.</p>
<p>So I did some Google searching, and found tons of resources where people had created their own Progress Bar controls.  While that was all fine and good, I wasn&#8217;t looking to download somebody else&#8217;s custom control, and I wasn&#8217;t going to make my own.  So I wanted to figure out how I could use existing ASP.Net and AJAX controls to accomplish this task.</p>
<p>It turned out to be easier than I thought it would be.</p>
<p>I knew that I needed the progress bar to show modally, so that the user would not be able to interact with the form during the postback.  So I decided to use the <strong>ModalPopupExtender</strong> AJAX control.</p>
<p>So first, I have my <strong>Button</strong>, the <strong>ModalPopupExtender</strong>, the <strong>Panel</strong> that the extender will display, the <strong>Script Manager</strong>, and a <strong>hidden</strong> control.</p>
<pre class="brush: xml;">
&lt;asp:ScriptManager ID=&quot;ScriptManager1&quot; runat=&quot;server&quot; /&gt;
&lt;asp:UpdatePanel ID=&quot;UpdatePanel1&quot; runat=&quot;server&quot;&gt;
    &lt;ContentTemplate&gt;
        &lt;div&gt;
            &lt;asp:Button ID=&quot;btnSubmit&quot; OnClick=&quot;btnSubmit_Click&quot; OnClientClick=&quot;StartProgressBar()&quot;
                     runat=&quot;server&quot; Text=&quot;Submit Time&quot; Width=&quot;170px&quot; /&gt;

            &lt;ajaxToolkit:ModalPopupExtender ID=&quot;ProgressBarModalPopupExtender&quot; runat=&quot;server&quot;
                     BackgroundCssClass=&quot;ModalBackground&quot; BehaviorID=&quot;ProgressBarModalPopupExtender&quot;
                     TargetControlID=&quot;hiddenField&quot; PopupControlID=&quot;Panel1&quot; /&gt;

            &lt;asp:Panel ID=&quot;Panel1&quot; runat=&quot;server&quot; Style=&quot;display: none; background-color: #C0C0C0;&quot;&gt;
                 &lt;img src=&quot;progressbar.gif&quot; alt=&quot;&quot; /&gt;
            &lt;/asp:Panel&gt;

            &lt;asp:HiddenField ID=&quot;hiddenField&quot; runat=&quot;server&quot; /&gt;
       &lt;/div&gt;
   &lt;/ContentTemplate&gt;
&lt;/asp:UpdatePanel&gt;
</pre>
<p>If you notice, the <strong>TargetControlID </strong>attribute of the extender is NOT the button.  The reason for this is that the default functionality of the <strong>ModalPopupExtender </strong>is to require a button click from the <strong>Panel </strong>to close it.  Since I want the <strong>Panel </strong>to stay visible while the server does it&#8217;s processing, I set the <strong>TargetControlID </strong>to the <strong>hidden </strong>control.</p>
<p>Another thing to notice is the <strong>BackgroundCssClass </strong>attribute of the <strong>ModalPopupExtender</strong>.  This is REQUIRED for the extender to actual be modal.  Without it, the extender is a non-modal popup.(more on this later)</p>
<p>Also notice that the <strong>Button </strong>has both of the click events populated.  The <strong>OnClick </strong>event will be the server-side event handler.</p>
<pre class="brush: csharp;">
protected void btnSubmit_Click(object sender, EventArgs e)
{
     Thread.Sleep(7000);
     ProgressBarModalPopupExtender.Hide();
}
</pre>
<p>This event simply pauses server processing for 7 seconds to simulate a long running process.</p>
<p>The <strong>OnClientClick </strong>event will be calling a javascript function&#8230;</p>
<pre class="brush: jscript;">
&lt;script language=&quot;javascript&quot; type=&quot;text/javascript&quot;&gt;
    function StartProgressBar() {
        var myExtender = $find('ProgressBarModalPopupExtender');
        myExtender.show();
        return true;
    }
&lt;/script&gt;
</pre>
<p>And last, the CSS entry for the background of the <strong>ModalPopupExtender</strong>.</p>
<p>If you do not already have a CSS class added to your project, you will need to add one, and link it to the page in the <strong>HEAD </strong>tag.</p>
<pre class="brush: xml;">
&lt;link href=&quot;main.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
</pre>
<p>Then add this entry to the CSS file.</p>
<pre class="brush: xml;">
.ModalBackground
{
    background-color:Gray;

    filter:alpha(opacity=50);
    -moz-opacity:0.5;
    -khtml-opacity: 0.5;
    opacity: 0.5;
}
</pre>
<p>If using Visual Studio 2008, you will get warnings saying that &#8220;filter&#8221; and &#8220;opacity&#8221; are not known CSS properties.  This is an issue with Visual Studio.  They are valid properties and they do work.  The 4 properties that are listed in the CSS entry should handle the opacity for all major browsers.  I have tested with IE7, Firefox 3.5, and Chrome.</p>
<p>And that is all you have to do.  The <strong>ModalPopupExtender </strong>will show when the button is clicked, and the server will start processing the code.  When the server has completed and sends the response back to the browser, it will hide the <strong>ModalPopupExtender</strong>.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/aspnet-ajax-continuous-progress-bar/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>C# &#8211; Download File Asynchronously with ProgressBar</title>
		<link>http://eclipsed4utoo.com/blog/c-download-file-asynchronously-with-progressbar/</link>
		<comments>http://eclipsed4utoo.com/blog/c-download-file-asynchronously-with-progressbar/#comments</comments>
		<pubDate>Fri, 31 Jul 2009 20:57:32 +0000</pubDate>
		<dc:creator>Ryan Alford</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[progressbar]]></category>

		<guid isPermaLink="false">http://eclipsed4utoo.com/blog/?p=56</guid>
		<description><![CDATA[If you&#8217;ve ever wanted to create your own Download Manager, where you download a file, keep track of the amount of the file that has been downloaded, and use a ProgressBar, this is the tutorial for you. So first, drag a ProgressBar and a Button from the Toolbox onto the form. Create a Click_Event for [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever wanted to create your own Download Manager, where you download a file, keep track of the amount of the file that has been downloaded, and use a ProgressBar, this is the tutorial for you.</p>
<p>So first, drag a ProgressBar and a Button from the Toolbox onto the form.</p>
<p>Create a Click_Event for the button by double clicking it.</p>
<p>Add this using statement to the top of the form.</p>
<pre class="brush: csharp;">
using System.Net;
</pre>
<p>In the Click_Event, we are going to create a <strong>WebClient</strong> object to download the file.</p>
<pre class="brush: csharp;">
private void btnStartDownload_Click(object sender, EventArgs e)
{
     WebClient client = new WebClient();
     client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
     client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);

     // Starts the download
     client.DownloadFileAsync(new Uri(&quot;SomeURLToFile&quot;), &quot;SomePlaceOnLocalHardDrive&quot;);

     btnStartDownload.Text = &quot;Download In Process&quot;;
     btnStartDownload.Enabled = false;
}
</pre>
<p>In the previous code, we are creating two event handlers to handle when the Progress of the file download changes, and when the download completes.</p>
<p>We also use the DownloadFileAsync method so that the download(which could be lengthy) does not freeze the main GUI.</p>
<p>Next, we need to do the code to calculate the percentage of the download complete so that we can assign it to the ProgressBar.</p>
<pre class="brush: csharp;">
void client_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
     double bytesIn = double.Parse(e.BytesReceived.ToString());
     double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
     double percentage = bytesIn / totalBytes * 100;

     progressBar1.Value = int.Parse(Math.Truncate(percentage).ToString());
}
</pre>
<p>In this code, we use the BytesReceived and TotalBytesToReceive properties of the DownloadProgressChangedEventArgs object.</p>
<p>Next, we need to do the code for the event when the download completes.</p>
<pre class="brush: csharp;">
void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
     MessageBox.Show(&quot;Download Completed&quot;);

     btnStartDownload.Text = &quot;Start Download&quot;;
     btnStartDownload.Enabled = true;
}
</pre>
<p>That is all the code you need.</p>
<p>If you would like to have the percentage &#8220;embedded&#8221; into the ProgressBar, check out <a href="http://www.dreamincode.net/forums/showtopic94631.htm">JacobJordan&#8217;s tutorial</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://eclipsed4utoo.com/blog/c-download-file-asynchronously-with-progressbar/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

