在wince中有个上传图片事件,现在有可能无线网络有问题,图片上传需要很久。想做个计时器,如果超过5秒,就报错。用线程来做以上功能,遇到了多线程带参数的问题,网上搜了一大把,不能用,求解public void Route_StartCamareEvent(string name)
{
//网上说可以用ParameterizedThreadStart,但是wince下没有这个
//求这边到底怎么传参数比较好
threadwcf =new Thread(new ThreadStart(wcfrun); threadtime = new Thread(new ThreadStart(timerun));
threadwcf.Start(name);//这边报错,貌似不可以这么用的
threadtime.Start();
} private void timerun()
{
for (var i = 3000; i > 0; i--)
{
if (i < 100)
{
this.statusBar1.Text = Status.wlanTimeOut;
threadwcf.Abort();
FTPClient ft = new FTPClient();
ft.CopyFiles(Path.PicPath, Path.TemporaryPath);
threadtime.Abort();
return;
}
Thread.Sleep(2);
}
} public void wcfrun(string name)
{
picCount.Add(name);
threadwcf.Abort();
threadtime.Abort();
}
{
//网上说可以用ParameterizedThreadStart,但是wince下没有这个
//求这边到底怎么传参数比较好
threadwcf =new Thread(new ThreadStart(wcfrun); threadtime = new Thread(new ThreadStart(timerun));
threadwcf.Start(name);//这边报错,貌似不可以这么用的
threadtime.Start();
} private void timerun()
{
for (var i = 3000; i > 0; i--)
{
if (i < 100)
{
this.statusBar1.Text = Status.wlanTimeOut;
threadwcf.Abort();
FTPClient ft = new FTPClient();
ft.CopyFiles(Path.PicPath, Path.TemporaryPath);
threadtime.Abort();
return;
}
Thread.Sleep(2);
}
} public void wcfrun(string name)
{
picCount.Add(name);
threadwcf.Abort();
threadtime.Abort();
}
解决方案 »
- Linq to sql 导出数据
- 我有两个窗体form1和form2,怎么在form2中点击按钮增加form1中ImageList1里面的图片,然后绑定到form1中的listview上面。
- C#与OpenMp
- 如何将SQL Server CE中的数据导入到Access数据库中?
- webform和winform的事件处理函数默认访问为什么不同 protected 和 Private
- 移动硬盘不能读取?why?
- 谁有常用的工具栏图标,如添加、删除、保存等,是32*32 16*16
- {"未能加载文件或程序集“SQLServerDAL”或它的某一个依赖项。系统找不到指定的文件。":"SQLServerDAL"} System.Exception {System.IO.FileNotFoundException
- WPF浏览器程序在IIS发布网站后出现这样奇怪的问题,哪位遇到过没有?
- 跪求大哥们:VS2005创建MSSQL数据库
- XDocument.Save("stu.xml");
- C#中怎么用listview显示指定路径下的文件和文件夹~
//
// 摘要:
// 使操作系统将当前实例的状态更改为 System.Threading.ThreadState.Running,并选择提供包含线程执行的方法要使用的数据的对象。
//
// 参数:
// parameter:
// 一个对象,包含线程执行的方法要使用的数据。
//
// 异常:
// System.Threading.ThreadStateException:
// 线程已启动。
//
// System.OutOfMemoryException:
// 没有足够的可用内存来启动此线程。
//
// System.InvalidOperationException:
// 此线程是使用 System.Threading.ThreadStart 委托(而不是 System.Threading.ParameterizedThreadStart
// 委托)创建的。
[SecuritySafeCritical]
public void Start(object parameter);
public void Start();这边 threadwcf.Start(name);//这边代码没改,肯定不是这么写的,参数不知道在哪传
using System;namespace System.Threading
{
// 摘要:
// 表示在 System.Threading.Thread 上执行的方法。
public delegate void ThreadStart();
}没有ParameterizedThreadStart,可以自己添加吗?
public void wcfrun(string name)
{
picCount.Add(name);
threadwcf.Abort();
threadtime.Abort();
}
改
public void wcfrun(object o)
{
string name=(string)o;
picCount.Add(name);
threadwcf.Abort();
threadtime.Abort();
}
如果你说的长时间没有连接上网络的话,设置超时就行了,一般网络相关的函数都有超时设定的。
线程中传参的例子
Thread t = new Thread(ThreadFun);
t.Start(new yourparam());
private void ThreadFun(object param)
{
yourparam y = param as yourparam;
....
}