document.write('<div class="csharp" style="font-family: monospace;"><br />');
document.write('<br />');
document.write('<span style="color: #0600FF;">namespace</span> DownloadApi.<span style="color: #0000FF;">Net</span><br />');
document.write('<span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; <span style="color: #008080;">#region [ Using Directives ]</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; <span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>;<br />');
document.write('&nbsp; &nbsp; <span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Collections</span>.<span style="color: #0000FF;">Generic</span>;<br />');
document.write('&nbsp; &nbsp; <span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Text</span>;<br />');
document.write('&nbsp; &nbsp; <span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">ComponentModel</span>;<br />');
document.write('&nbsp; &nbsp; <span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">Net</span>;<br />');
document.write('&nbsp; &nbsp; <span style="color: #0600FF;">using</span> <span style="color: #000000;">System</span>.<span style="color: #0000FF;">IO</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />');
document.write('<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> DownloadClient<br />');
document.write('&nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region [ Events ]</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> EventHandler Complete;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> EventHandler Cancelled;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">event</span> EventHandler&lt;ProgressChangedEventArgs&gt; ProgressChanged;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ProgressChangedEventArgs : EventArgs<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region [ Properties ]</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> Int32 _Progress;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> Int32 Progress<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; get <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">return</span> _Progress; <span style="color: #000000;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set <span style="color: #000000;">&#123;</span> _Progress = value; <span style="color: #000000;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />');
document.write('<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region [ Constructor ]</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> ProgressChangedEventArgs<span style="color: #000000;">&#40;</span>Int32 progress<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Progress</span> = progress;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />');
document.write('<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region [ Field ]</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> BackgroundWorker _backgroundWorker = <span style="color: #0600FF;">null</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />');
document.write('<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region [ Constructor ]</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> DownloadClient<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span> <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />');
document.write('<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region [ Methods ]</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Start<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span> url, <span style="color: #FF0000;">String</span> path, Int32 startPoint<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List&lt;Object&gt; arguments = <a target="_blank"&nbsp; href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List&lt;Object&gt;<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arguments.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>url<span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arguments.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>path<span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; arguments.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>startPoint<span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _backgroundWorker = CreateWorker<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _backgroundWorker.<span style="color: #0000FF;">RunWorkerAsync</span><span style="color: #000000;">&#40;</span>arguments<span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Cancel<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _backgroundWorker.<span style="color: #0000FF;">CancelAsync</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> DoWork<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> sender, DoWorkEventArgs e<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; List&lt;Object&gt; arguments = <span style="color: #000000;">&#40;</span>List&lt;Object&gt;<span style="color: #000000;">&#41;</span>e.<span style="color: #0000FF;">Argument</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HttpWebRequest req = <span style="color: #0600FF;">null</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; HttpWebResponse res = <span style="color: #0600FF;">null</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stream resStream = <span style="color: #0600FF;">null</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Stream localStream = <span style="color: #0600FF;">null</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">try</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; req = <span style="color: #000000;">&#40;</span>HttpWebRequest<span style="color: #000000;">&#41;</span>WebRequest.<span style="color: #0000FF;">Create</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span><span style="color: #000000;">&#41;</span>arguments<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">0</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; req.<span style="color: #0000FF;">ContentType</span> = <span style="color: #808080;">&quot;Application&quot;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; req.<span style="color: #0000FF;">AddRange</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>Int32<span style="color: #000000;">&#41;</span>arguments<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; req.<span style="color: #0000FF;">Credentials</span> = CredentialCache.<span style="color: #0000FF;">DefaultCredentials</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res = <span style="color: #000000;">&#40;</span>HttpWebResponse<span style="color: #000000;">&#41;</span>req.<span style="color: #0000FF;">GetResponse</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Int64 fileSize = res.<span style="color: #0000FF;">ContentLength</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resStream = res.<span style="color: #0000FF;">GetResponseStream</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>Int32<span style="color: #000000;">&#41;</span>arguments<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span> == <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; localStream = <a target="_blank"&nbsp; href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FileStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span><span style="color: #000000;">&#41;</span>arguments<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span>, FileMode.<span style="color: #0000FF;">Create</span>, FileAccess.<span style="color: #0000FF;">Write</span>, FileShare.<span style="color: #0000FF;">None</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">else</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; localStream = <a target="_blank"&nbsp; href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> FileStream<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">String</span><span style="color: #000000;">&#41;</span>arguments<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">1</span><span style="color: #000000;">&#93;</span>, FileMode.<span style="color: #0000FF;">Append</span>, FileAccess.<span style="color: #0000FF;">Write</span>, FileShare.<span style="color: #0000FF;">None</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">int</span> bytesSize = <span style="color: #FF0000;">0</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> downBuffer = <a target="_blank"&nbsp; href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2048</span><span style="color: #000000;">&#93;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">while</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>bytesSize = resStream.<span style="color: #0000FF;">Read</span><span style="color: #000000;">&#40;</span>downBuffer, <span style="color: #FF0000;">0</span>, downBuffer.<span style="color: #0000FF;">Length</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> &gt; <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; localStream.<span style="color: #0000FF;">Write</span><span style="color: #000000;">&#40;</span>downBuffer, <span style="color: #FF0000;">0</span>, bytesSize<span style="color: #000000;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _backgroundWorker.<span style="color: #0000FF;">ReportProgress</span><span style="color: #000000;">&#40;</span>Convert.<span style="color: #0000FF;">ToInt32</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>localStream.<span style="color: #0000FF;">Length</span> * <span style="color: #FF0000;">100</span><span style="color: #000000;">&#41;</span> / fileSize + <span style="color: #000000;">&#40;</span>Int32<span style="color: #000000;">&#41;</span>arguments<span style="color: #000000;">&#91;</span><span style="color: #FF0000;">2</span><span style="color: #000000;">&#93;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_backgroundWorker.<span style="color: #0000FF;">CancellationPending</span><span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e.<span style="color: #0000FF;">Cancel</span> = <span style="color: #0600FF;">true</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">break</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#123;</span> <span style="color: #0600FF;">throw</span>; <span style="color: #000000;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">finally</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span> != req<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; req = <span style="color: #0600FF;">null</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span> != res<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span> != resStream<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resStream.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span> != localStream<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; localStream.<span style="color: #0000FF;">Close</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> WorkerProgressChanged<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> sender, <span style="color: #000000;">System</span>.<span style="color: #0000FF;">ComponentModel</span>.<span style="color: #0000FF;">ProgressChangedEventArgs</span> e<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OnProgressChanged<span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">ProgressPercentage</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> WorkerCompleted<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">Object</span> sender, RunWorkerCompletedEventArgs e<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span> != e.<span style="color: #0000FF;">Error</span><span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">throw</span> <a target="_blank"&nbsp; href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Exception<span style="color: #000000;">&#40;</span><span style="color: #808080;">&quot;Operation cancelled!&quot;</span>, e.<span style="color: #0000FF;">Error</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Cancelled</span><span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OnCancelled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">else</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OnComplete<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />');
document.write('<br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#region [ Helper Methods ]</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> OnProgressChanged<span style="color: #000000;">&#40;</span>Int32 progress<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EventHandler&lt;ProgressChangedEventArgs&gt; copy = ProgressChanged;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span> != copy<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; copy<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, <a target="_blank"&nbsp; href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ProgressChangedEventArgs<span style="color: #000000;">&#40;</span>progress<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> OnComplete<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EventHandler copy = Complete;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span> != copy<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; copy<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, EventArgs.<span style="color: #0000FF;">Empty</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> OnCancelled<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EventHandler copy = Cancelled;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #0600FF;">null</span> != copy<span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; copy<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span>, EventArgs.<span style="color: #0000FF;">Empty</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">public</span> BackgroundWorker CreateWorker<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#123;</span><br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; BackgroundWorker bg = <a target="_blank"&nbsp; href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> BackgroundWorker<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bg.<span style="color: #0000FF;">WorkerReportsProgress</span> = <span style="color: #0600FF;">true</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bg.<span style="color: #0000FF;">WorkerSupportsCancellation</span> = <span style="color: #0600FF;">true</span>;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bg.<span style="color: #0000FF;">DoWork</span> += DoWork;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bg.<span style="color: #0000FF;">ProgressChanged</span> += WorkerProgressChanged;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bg.<span style="color: #0000FF;">RunWorkerCompleted</span> += WorkerCompleted;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0600FF;">return</span> bg;<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008080;">#endregion</span><br />');
document.write('&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />');
document.write('<span style="color: #000000;">&#125;</span><br />');
document.write('<br />');
document.write('&nbsp;</div>');
document.write('<br />&nbsp;<br /><div style="font-size: 12px">Brought to you by the community at <a href="http://www.bytemycode.com/snippets/snippet/644/1/" target="_blank">byteMyCode</a>.</div>');
