C#通过循环来创建线程的几点疑问
通过循环创建的线程发生了异常,不知如何解释,我的代码是这样的:
创建的线程类:
class ProcessFile { //省略部分代码 public void FileProcessThread() { //.........省略部分代码 //访问文件夹,获取文件列表并进行文件处理 for (int i = 0; i < folderinfoTable.Rows.Count;i++ ) { Thread proProcess = new Thread(new ParameterizedThreadStart(mcdprofileProcess)); proProcess.Start(folderinfoTable.Rows[i]); } } void mcdprofileProcess(object objdr) { VersionManage versionmanage = new VersionManage(localdbconnstr); //........ bool ismatch=versionmanage.CheckVersionmatch(mcdlocalfilelistforversion[0].FullName, mcdVersion); } }线程方法调用的类:class VersionManage { //数据库连接 DBOperation dboperation; public VersionManage(string connectionstring) { dboperation = new DBOperation(connectionstring); }public bool CheckVersionmatch(string filepath,string VersionName) { //获取该版本类型的数量的sql语句 string getVernumstr = "SELECT COUNT(*) FROM(SELECT dbo.FILE_VERSION.Version_Name FROM dbo.FILE_VERSION GROUP BY Version_Name) AS temp WHERE temp.Version_Name='" + VersionName + "'"; [color=#FF0000] object vernumobj = dboperation.ExecuateScalar(getVernumstr);[/color] //.......................(省略) }}