征询意见,有做过类似FLASHGET,网络蚂蚁等下载管理工具得请进,菜鸟请不要UP 怎么处理多线程? ---- 实际上就是将每一个线程要读取得位置记录到一个临时文件,或者变量当中,然后,线程同步,协调分配线程任务3、象FLASHGET,网络蚂蚁的具体文件下载信息表示区用什么控件好,还是自己绘图?----自己绘图多方便。。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我是菜鸟我就要up我up了*********************……%……¥%¥(**()(*(*—·#—……¥—……¥*#· 我是菜鸟我就要up我up了*********************……%……¥%¥(**()(*(*—·#—……¥—……¥*#·--------------------------------------------------- 同意! 4using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;using System.Threading;namespace ch9_6{ /// <summary> /// Form1 的摘要说明。 /// </summary> public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Label label1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Label label2; private System.Windows.Forms.Label label4; private System.Windows.Forms.Label label3; private System.Windows.Forms.ComboBox comboBox1; private System.Windows.Forms.ComboBox comboBox2; private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.Label label5; /// <summary> /// 必需的设计器变量。 /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); this.comboBox1.SelectedIndex=1; this.comboBox2.SelectedIndex=1; // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.label1 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.label2 = new System.Windows.Forms.Label(); this.label4 = new System.Windows.Forms.Label(); this.label3 = new System.Windows.Forms.Label(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.comboBox2 = new System.Windows.Forms.ComboBox(); this.richTextBox1 = new System.Windows.Forms.RichTextBox(); this.label5 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // label1 // this.label1.Location = new System.Drawing.Point(16, 16); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(88, 16); this.label1.TabIndex = 0; this.label1.Text = "线程1当前数字"; // // button1 // this.button1.Location = new System.Drawing.Point(200, 72); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(72, 23); this.button1.TabIndex = 1; this.button1.Text = "开始"; this.button1.Click += new System.EventHandler(this.button1_Click); // // label2 // this.label2.Location = new System.Drawing.Point(128, 16); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(48, 16); this.label2.TabIndex = 2; // // label4 // this.label4.Location = new System.Drawing.Point(128, 48); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(48, 16); this.label4.TabIndex = 6; // // label3 // this.label3.Location = new System.Drawing.Point(16, 48); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(88, 16); this.label3.TabIndex = 5; this.label3.Text = "线程2当前数字"; // // comboBox1 // this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox1.Items.AddRange(new object[] { "高", "正常", "低"}); this.comboBox1.Location = new System.Drawing.Point(200, 8); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(72, 20); this.comboBox1.TabIndex = 7; // // comboBox2 // this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.comboBox2.Items.AddRange(new object[] { "高", "正常", "低"}); this.comboBox2.Location = new System.Drawing.Point(200, 40); this.comboBox2.Name = "comboBox2"; this.comboBox2.Size = new System.Drawing.Size(72, 20); this.comboBox2.TabIndex = 8; // // richTextBox1 // this.richTextBox1.Location = new System.Drawing.Point(0, 96); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.Size = new System.Drawing.Size(288, 312); this.richTextBox1.TabIndex = 9; this.richTextBox1.Text = ""; // // label5 // this.label5.Location = new System.Drawing.Point(16, 80); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(100, 16); this.label5.TabIndex = 10; this.label5.Text = "结果显示"; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 421); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.label5, this.richTextBox1, this.comboBox2, this.comboBox1, this.label4, this.label3, this.label2, this.button1, this.label1}); this.Name = "Form1"; this.Text = "多线程调度"; this.ResumeLayout(false); } #endregion /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } public void HandleThread1() { for (int i=0;i<10;i++) { for (int j=1;j<100;j++) { this.label2.Text=i.ToString(); } //在richTextBox1中输出 this.richTextBox1.Text+="来自线程1的数字:"+i.ToString()+"\n"; } } public void HandleThread2() { for (int i=0;i<10;i++) { for (int j=1;j<100;j++) { this.label4.Text=i.ToString(); } //在richTextBox1中输出 this.richTextBox1.Text+="来自线程2的数字:"+i.ToString()+"\n"; } } private void button1_Click(object sender, System.EventArgs e) { //创建线程1和线程2的实例 Thread th1=new Thread(new ThreadStart(HandleThread1)); Thread th2=new Thread(new ThreadStart(HandleThread2)); this.richTextBox1.Text=""; int i=this.comboBox1.SelectedIndex; //设置线程1优先级 switch (i.ToString()) { case "0": th1.Priority=ThreadPriority.AboveNormal; break; case "1": th1.Priority=ThreadPriority.Normal; break; case "2": th1.Priority=ThreadPriority.BelowNormal; break; } int j=this.comboBox2.SelectedIndex; //设置线程2优先级 switch (j.ToString()) { case "0": th2.Priority=ThreadPriority.AboveNormal; break; case "1": th2.Priority=ThreadPriority.Normal; break; case "2": th2.Priority=ThreadPriority.BelowNormal; break; } //启动线程 th1.Start(); th2.Start(); } }} 谢谢haonanernet(好男儿) ,但是应用的时候不是这么简单,大家可以看看FLASHGET,他可以启动十个线程去下载文件,不知大家有何想法。 谁帮我看下这个递归问题 数据库上百万条,内部排序的原理是什么。 在c#中怎样建立文件夹 c#连接带有密码的ACCESS数据库 关于汉字编码问题!求解 一个算法问题 请问怎么用session实现购物车 用什么办法把str转换成MouseEventArgs或者EventArgs类型?本人菜鸟,求高手解决 求救!我的系统是WIN2000SERVER,安装完VS2003后,MSDN不能用! 复合控件中,第一次运行时子控件 DataGrid 触发不出来 SortCommand 事件 datalist的简单问题,新人勿笑我 datagrid 隐藏列
我就要up
我up了
*********************……%……¥%¥(**()(*(*—·#—……¥—……¥*#·
我就要up
我up了
*********************……%……¥%¥(**()(*(*—·#—……¥—……¥*#·
---------------------------------------------------
同意!
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;using System.Threading;namespace ch9_6
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.ComboBox comboBox2;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.Label label5;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.comboBox1.SelectedIndex=1;
this.comboBox2.SelectedIndex=1; //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.label2 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.comboBox1 = new System.Windows.Forms.ComboBox();
this.comboBox2 = new System.Windows.Forms.ComboBox();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.label5 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(88, 16);
this.label1.TabIndex = 0;
this.label1.Text = "线程1当前数字";
//
// button1
//
this.button1.Location = new System.Drawing.Point(200, 72);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(72, 23);
this.button1.TabIndex = 1;
this.button1.Text = "开始";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label2
//
this.label2.Location = new System.Drawing.Point(128, 16);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(48, 16);
this.label2.TabIndex = 2;
//
// label4
//
this.label4.Location = new System.Drawing.Point(128, 48);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(48, 16);
this.label4.TabIndex = 6;
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 48);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(88, 16);
this.label3.TabIndex = 5;
this.label3.Text = "线程2当前数字";
//
// comboBox1
//
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox1.Items.AddRange(new object[] {
"高",
"正常",
"低"});
this.comboBox1.Location = new System.Drawing.Point(200, 8);
this.comboBox1.Name = "comboBox1";
this.comboBox1.Size = new System.Drawing.Size(72, 20);
this.comboBox1.TabIndex = 7;
//
// comboBox2
//
this.comboBox2.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
this.comboBox2.Items.AddRange(new object[] {
"高",
"正常",
"低"});
this.comboBox2.Location = new System.Drawing.Point(200, 40);
this.comboBox2.Name = "comboBox2";
this.comboBox2.Size = new System.Drawing.Size(72, 20);
this.comboBox2.TabIndex = 8;
//
// richTextBox1
//
this.richTextBox1.Location = new System.Drawing.Point(0, 96);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(288, 312);
this.richTextBox1.TabIndex = 9;
this.richTextBox1.Text = "";
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 80);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(100, 16);
this.label5.TabIndex = 10;
this.label5.Text = "结果显示";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 421);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.label5,
this.richTextBox1,
this.comboBox2,
this.comboBox1,
this.label4,
this.label3,
this.label2,
this.button1,
this.label1});
this.Name = "Form1";
this.Text = "多线程调度";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} public void HandleThread1()
{
for (int i=0;i<10;i++)
{
for (int j=1;j<100;j++)
{
this.label2.Text=i.ToString();
}
//在richTextBox1中输出
this.richTextBox1.Text+="来自线程1的数字:"+i.ToString()+"\n";
}
}
public void HandleThread2()
{
for (int i=0;i<10;i++)
{
for (int j=1;j<100;j++)
{
this.label4.Text=i.ToString();
}
//在richTextBox1中输出
this.richTextBox1.Text+="来自线程2的数字:"+i.ToString()+"\n";
}
}
private void button1_Click(object sender, System.EventArgs e)
{
//创建线程1和线程2的实例
Thread th1=new Thread(new ThreadStart(HandleThread1));
Thread th2=new Thread(new ThreadStart(HandleThread2));
this.richTextBox1.Text="";
int i=this.comboBox1.SelectedIndex;
//设置线程1优先级
switch (i.ToString())
{
case "0":
th1.Priority=ThreadPriority.AboveNormal;
break;
case "1":
th1.Priority=ThreadPriority.Normal;
break;
case "2":
th1.Priority=ThreadPriority.BelowNormal;
break;
}
int j=this.comboBox2.SelectedIndex;
//设置线程2优先级
switch (j.ToString())
{
case "0":
th2.Priority=ThreadPriority.AboveNormal;
break;
case "1":
th2.Priority=ThreadPriority.Normal;
break;
case "2":
th2.Priority=ThreadPriority.BelowNormal;
break;
}
//启动线程
th1.Start();
th2.Start();
}
}
}
线程去下载文件,不知大家有何想法。