好心人能帮我看一下这个程序吗?
我想实现自动上传,就是一启动这个程序后每隔一定时间上传一次(因为这个目录下随时可能有新的文件产生),可是线程好像没有启动,也就是不能上传到服务器,如果不使用线程的话可以实现手动上传,但这不是我所要的,我要的是自动上传。是那里出了问题吗?
static void Main()
{
Application.Run(new Form1());
}
public void StartThread()//开始启动一个新线程
{
try
{
newThread=new System.Threading.Thread(new ThreadStart(ReceiveMessage_1));//ReceiveMessage线程要做的工作放在这个函数里面
newThread.Start();
}
catch(Exception ex)
{
}
}
private void ReceiveMessage_1()
{
//这里开始写你要执行的操作
//////////////////////////
FTPFactory ff = new FTPFactory();
ff.setDebug(true);
ff.setRemoteHost("172.22.68.4");
ff.setRemoteUser("webipp");
ff.setRemotePass("");
ff.login();
ff.chdir("bt\\hnny");
foreach(string Fn in Directory.GetFiles(@"d:\hnny","*.*"))
{
if (File.Exists(Fn))
ff.upload(Fn);
}
System.Threading.Thread.Sleep(5000);//线程等待0.5分钟
this.newThread.Abort();
this.StartThread();//再次启动线程
}
private void button1_Click(object sender, System.EventArgs e)
{
FTPFactory ff = new FTPFactory();
ff.setDebug(true);
ff.setRemoteHost("172.22.68.4");
ff.setRemoteUser("webipp");
ff.setRemotePass("");
ff.login();
ff.chdir("bt\\hnny");
foreach(string Fn in Directory.GetFiles(@"d:\hnny","*.*"))
{
if (File.Exists(Fn))
ff.upload(Fn);
}
ff.close();
}