WinForm窗体中发短信要实现一个进度条,找了一个是用循环做的,进度条的速度太快了,效果不好,怎么实现效果会好一些?用backgroundWorker,具体怎么实现,能否附上一些代码?
解决方案 »
- 请问一个session的问题?
- 请问下面几个headers怎么提交
- 请教,关于用类关系图创建代码结构的问题
- 急!请问C#如何控制一个别人写的.net的Window Form应用程序的界面输入和按钮模拟??谢谢!
- 怎样才能学好C#
- PrintDocument 打印richtextbox 里面的内容的时候 行超越过纸张 请问如何解决
- 如何在C#中使用SQL的存储过程和如何在C#中调EXCEL
- 200分求一个非技术的关于Developer Express控件的问题,顶者有分.100分送顶贴人,100分送答题人.
- 求一个:两个时间之差的函数 ,帮忙写一下参数的意义,多谢各位大哥
- 求助:关于继承控件时显示不出来自己添加的控件
- [高分求解]dsoframer.ocx 打开一个excel文件后,我别的部打开excel文件时不行编辑[卡死状况],怎样解决。
- 怎么通过代码能把DEV控件组里的gridview 控件全部展开分组?
public class PublishHelper
{
private static PublishHelper helper;
public static PublishHelper Instance
{
get
{
if ( helper == null )
{
helper = new PublishHelper();
}
return helper;
}
}
/// <summary>
/// 获取文件列表
/// </summary>
/// <param name="BaseDir">APP地址</param>
/// <returns>List列表</returns>
public AssemblyInfoFileList GetFileList( string BaseDir )
{
AssemblyInfoFileList afl = GetClientUpdateList( BaseDir );
return afl;
} /// <summary>
/// 私有方法,递归数据给上面客户端列表
/// </summary>
/// <param name="BaseDir">APP地址</param>
/// <returns>List列表</returns>
private AssemblyInfoFileList GetClientUpdateList( string BaseDir )
{
if ( String.IsNullOrEmpty( BaseDir ) )
{
BaseDir = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, "UpdateClient" );
} return AssemblyHelper.GetAssemblyList( BaseDir );
}
/// <summary>
/// 进行文件COPY的方法[线程回调]
/// </summary>
/// <param name="filelist">文件列表</param>
/// <param name="UserPath">用户选择的路径</param>
/// <param name="bar">进度条</param>
/// <param name="lab">标签条</param>
public void ShareSession( AssemblyInfoFileList filelist, string UserPath, string publishPath,ProgressBar bar, Label lab )
{
int cm = 100 / filelist.Count; if ( File.Exists( AssemblyHelper.AssemblyListFileName ) ) File.Delete( AssemblyHelper.AssemblyListFileName );
//string AppPath =Path.Combine( System.AppDomain.CurrentDomain.BaseDirectory, "UpdateClient" );
string AppPath = Path.Combine(publishPath, "UpdateClient");
if (!Directory.Exists(AppPath))
{
Directory.CreateDirectory(AppPath);
}
foreach ( AssemblyInfoFile temp in filelist )
{
if ( bar.Value < 100 ) { bar.Value += cm; }
lab.Text = "正在下载:" + temp.RelativePath;
string remoteFileName = temp.RelativePath;
if ( remoteFileName.IndexOf( "\\" ) > 0 )
{
string file = remoteFileName.Substring( remoteFileName.LastIndexOf( "\\" ) + 1, remoteFileName.Length - remoteFileName.LastIndexOf( "\\" ) - 1 );
string[] spli = { "\\" + file };
string path = remoteFileName.Split( spli, StringSplitOptions.RemoveEmptyEntries )[ 0 ];
if ( !Directory.Exists( Path.Combine( AppPath, path ) ) )
{
Directory.CreateDirectory( Path.Combine( AppPath, path ) );
}
}
File.Copy( Path.Combine( UserPath, remoteFileName ), Path.Combine( AppPath, remoteFileName ), true );
}
bar.Value = 100;
lab.Text = "文件更新成功完成";
} }
界面调用:string strAppCode = this.tslAppCode.Text; if ( this.UpdatedFile.Count == 0 || String.IsNullOrEmpty( strAppCode ) || strAppCode == "应用系统" )
{
return;
} try
{
if ( MessageBox.Show( String.Format( "您确定要更新文件夹{0}下的{1}个文件到{2}系统么? ", this.LocalRootDirectory.FullName,
this.UpdatedFile.Count, strAppCode ), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question )
== DialogResult.No )
return; tsbUpdate.Enabled = false;
ProgressBarStatus.Visible = true;
ProgressBarStatus.Maximum = UpdatedFile.Count;
ProgressBarStatus.Value = 0; helper.UploadWholeDir = false;
helper.UploadFile( this.UpdatedFile, strAppCode ); MessageBox.Show( "更新服务完成", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information );
}
catch ( Exception ex )
{
MessageBox.Show( "更新失败" + ex.Message, "提示", MessageBoxButtons.OK, MessageBoxIcon.Error );
LogManager.WriteError( ex );
}
finally
{
ProgressBarStatus.Visible = false;
this.labelInfo.Text = "就绪";
tsbUpdate.Enabled = true;
}
delegate void ShowProBar(int i);private void button1_Click(object sender, EventArgs e)
{
th1 = new Thread(new ThreadStart(test1));
th1.Start();
}
private void test1()
{
int i = 100;
while (i > -1)
{
setvalue1(i);
ShowProgress1(i);
i--;
Thread.Sleep(1000);
}
}
private void setvalue1(int i)
{
if (this.InvokeRequired)
{
this.Invoke(new SetValues(setvalue1), new object[] {i});
}
else
{
自己的操作
}
}
private void ShowProgress1(int i)
{
if (this.progressBar1.InvokeRequired)
{
this.Invoke(new ShowProBar(ShowProgress1), new object[] { i });
}
else
{
progressBar1.Value = 100-i;
progressBar1.Visible=true;
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;namespace WinTestUrl
{
public delegate void SetPos(int ipos);
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
} public void SetTextMessage(int ipos)
{
if (this.InvokeRequired)
{
SetPos setpos = new SetPos(SetTextMessage);
this.Invoke(setpos, new object[] { ipos });
}
else
{
this.label1.Text = ipos.ToString() + "/10";
this.progressBar1.Value = Convert.ToInt32(ipos);
}
} public void button2_Click(object sender, EventArgs e)
{
Thread fThread = new Thread(new ThreadStart(SleepT));//开辟一个新的线程
fThread.Start();
} public void SleepT()
{
for (int i = 1; i <= 100; i++)
{
System.Threading.Thread.Sleep(100);//没什么意思,单纯的执行延时
SetTextMessage(10 * i / 100);
}
}
}
}