当前位置:首页 >> 电力/水利 >>

C# progressBar进度条--实时


C# progressBar 进度条--实时 2009-02-23 13:15using System;

using using using using using using using using using

System.Collections.Generic; System.ComponentModel; System.Data

; System.Drawing; System.Text; System.Windows.Forms; System.IO; System.Threading; System.Reflection;

namespace DataBackup { public partial class FrmBackup : Form { /// <summary> /// Self_Variable: progressBar 进度条 /// </summary> private delegate void sprogressBar(); public FrmBackup() { InitializeComponent(); }

#region 本类全局变量 /// <summary> /// Self_Object:其它操作方法对象 /// </summary> BackOther other = new BackOther(); /// <summary> /// Self_Variable:统计总字节数 /// </summary> private int totalSize = 0; /// <summary> /// Self_Variable:剩余字节数 /// </summary>

private int position = 0; /// <summary> /// Self_Variable:字节数对比 /// </summary> private const int BUFFER_SIZE = 4096; /// <summary> /// buffer 字节数组 /// </summary> private byte[] buffer; /// <summary> /// Self_Variable:字节视图 /// </summary> private Stream stream; #endregion

#region 备



private void button1_Click(object sender, EventArgs e) { //创建文件夹 other.FileExists(); //备份路径 string dbpath = "..\\..\\..\\Data\\gs_back_gw680.mdb"; //源数据库路径 string sourcepath = "..\\gs_gw680.mdb"; //创建备份数据库 BackOther.CreateAccess(dbpath); //压缩源数据库 BackOther.CompactAccess(sourcepath); FileStream fs = new FileStream(sourcepath, FileMode.Open, FileAccess.Read); totalSize = Convert.ToInt32(fs.Length); stream = fs; if (totalSize > BUFFER_SIZE) { buffer = new byte[BUFFER_SIZE]; stream.BeginRead(buffer, 0, BUFFER_SIZE, new AsyncCallback(AsyncCopyFile), null);

} else { fs.Close(); } } #endregion

#region 异步方法 /// <summary> /// Asynchronously copy file /// </summary> /// <param name="ar"></param> private void AsyncCopyFile(IAsyncResult ar) { int readedLength; // Lock FileStream lock (stream) { readedLength = stream.EndRead(ar); // When stream endread, get readed length } // Write to disk string dbpath = "..\\..\\..\\Data\\gs_back_gw680.mdb"; FileStream fsWriter = new FileStream(dbpath, FileMode.Append, FileAccess.Write); fsWriter.Write(buffer, 0, buffer.Length); fsWriter.Close(); // Current stream position position += readedLength; //调用委托实现 progressBar 进度条 progressBar.BeginInvoke(new sprogressBar(SynchProgressBar)); // Read over. if (position >= totalSize) { //Close FileStream

stream.Close(); MessageBox.Show("备份完成!"); //忽略线程中的某些异常调用 Control.CheckForIllegalCrossThreadCalls = false; this.btnBack.Enabled = false; this.progressBar.Maximum = 0; this.progressBar.Value = 0; return; }

// Continue to read and write lock (stream) { int leftSize = totalSize - position; if (leftSize < BUFFER_SIZE) buffer = new byte[leftSize]; stream.BeginRead(buffer, AsyncCallback(AsyncCopyFile), null); } } 0, buffer.Length, new

/// <summary> /// Self_Function:修改进度条信息 /// </summary> private void SynchProgressBar() { this.progressBar.Maximum = totalSize; this.progressBar.Value = position; } #endregion } }


相关文章:
进度条代码
代码来 C# code #region MarqueeProcess 显示连续滚动的进度条 /// /// 显示...{ this.progressBar1.Style = ProgressBarStyle.Blocks; this.progressBar1....
C#进度条的使用
C#进度条的使用_计算机软件及应用_IT/计算机_专业资料。C#进度条的使用,附有垂直...{ // Inserts code to copy a file progressBar1.PerformStep(); // Updates...
C#_进度条控件ProgressBar_和列表试图控件LiseView
C#_进度条控件ProgressBar_和列表试图控件LiseView_计算机软件及应用_IT/计算机_专业资料。C# 相关资料C# 进度条控件 ProgressBar 和列表试图控件 LiseView - 叶子 -...
C#源代码实现进度条功能
C#源代码实现进度条功能_IT/计算机_专业资料。GProgressBar,是一个进度条控件,能够设置进度条的背景色和前景色,设置进度条的外观方式(3d,single,none),是否自动显示...
c#进度条
c#进度条_计算机软件及应用_IT/计算机_专业资料。c#代码实现进度条c# 进度条的使用(例子) 在用 c#做 WinFrom 开发的过程中。我们经常需要用到进度条(ProgressBar)...
jQuery-EasyUI基础教程之Progressbar进度条
jQuery-EasyUI基础教程之Progressbar进度条_计算机软件及应用_IT/计算机_专业资料。掌握Progressbar的使用方法 http://xueyuan.lanqiao.org jQuery-EasyUI 基础教程之 ...
C#中进度条的使用
C#进度条的使用_计算机软件及应用_IT/计算机_专业资料。C#进度条的使用如果...{ progressBar1.Value = e.ProgressPercentage; } } //模拟耗时较长的任务 /...
利用Visual C#打造一个平滑的进度条
ProgressBarColor。该属性表示了进度条的颜色。 建立一个自定义的进度条控件 1、按着下面的步骤,在 Visual C# .NET 中建立一个 Windows Control Library 项目: a...
C#异步进度条程序
C#异步进度条程序_IT/计算机_专业资料。C# winform 程序开发异步进度条调用示例主...(dataGridView1.InvokeRequired || progressBar1.InvokeRequired) { SetTextCallback...
C#带进度条查询文件
C#使用进度条ProgressBa... 2页 免费C​#​带​进​度​条​查​...{ progressBar1.Maximum = 100000; comboBox1.Items.Add("C:"); comboBox1....
更多相关标签:
c 进度条progressbar | c progressbar 实时 | c 进度条不实时刷新 | progressbar进度条 | ajax 加载实时进度条 | java web实时进度条 | ajax实时刷新进度条 | jquery实时进度条 |