初学Form,有些不明白,这个是什么原因?
“未处理的“System.NullReferenceException”类型的异常出现在 WindowsApplication1.exe 中。
其他信息: 未将对象引用设置到对象的实例。”
上面是错误提示信息,
数字怎么引用呢?
//定义5个线程类;
public System.Threading.Thread m_thdone;
public System.Threading.Thread m_thdtwo;
public System.Threading.Thread m_thdthree;
public System.Threading.Thread m_thdfour;
public System.Threading.Thread m_thdfive;
private void Form1_Load(object sender, System.EventArgs e)
{
}
//button 事件
private void button1_Click(object sender, System.EventArgs e)
{
button1.Enabled=false;
button2.Enabled=true;
m_thdone=new System.Threading.Thread(new System.Threading.ThreadStart(this.TheadOne));
m_thdone=new System.Threading.Thread(new System.Threading.ThreadStart(this.ThreadTwo));
m_thdone=new System.Threading.Thread(new System.Threading.ThreadStart(this.ThreadThree));
m_thdone=new System.Threading.Thread(new System.Threading.ThreadStart(this.ThreadFour));
m_thdone=new System.Threading.Thread(new System.Threading.ThreadStart(this.ThreadFive));
m_thdone.Start();
m_thdtwo.Start();
m_thdthree.Start();
m_thdfour.Start();
m_thdfive.Start();
}
private void textBox1_TextChanged(object sender, System.EventArgs e)
{
}
//线程起用;
public void TheadOne()
{
button1.Enabled=false;
string Url=textBox1.Text;//获取Url地址
int n=Url.LastIndexOf('/');
string UrlAddress=Url.Substring(0,n);
string fileName=Url.Substring(n+1,Url.Length-n-1);
string Dir=textBox6.Text;
string Path=Dir+"\\"+fileName;
try
{
WebRequest myre= WebRequest.Create(UrlAddress);
}
catch(WebException exp)
{
MessageBox.Show(exp.Message,"Error!!");
}
try
{
statusBar1.Text="下载文件......";
client.DownloadFile(UrlAddress,Path);//实现下载;
statusBar1.Text="下载完毕,恭喜!!!";
}
catch(WebException exp)
{
MessageBox.Show(exp.Message,"下载失败!尝试别的路径!!");
statusBar1.Text="下载失败!尝试别的路径!!";
}
button1.Enabled=true;
}