你是问如果一个方法有参数怎么用线程调用是吗?
XmlDocument doc = new XmlDocument();
//传一个无参的方法
Thread th = new Thread(new ThreadStart(DownloadData));
th.IsBackground = true;
th.Start();
//利用方法的重载将将有参数的方法放到它的重载方法中,然后交给线程调用
private void DownloadData()
{
DownloadData(doc);
}
private void DownloadData(XmlDocument doc)
{
WebClient myWebClient = new WebClient();
foreach (XmlNode item in doc.SelectNodes("/tables"))
{
foreach (XmlNode node in item)
{
foreach (XmlNode node_Child in node)
{
#region 从表中得到字段的值,根据值下载
if (node.Name == "GXS_PATIENT_INFO" && node_Child.Name == "SELECTSQL")
{
table = esql.ExecuteSelectSQLStr(string.Format(node_Child.InnerText, Model.gXSID));
for (int i = 0; i < table.Rows.Count; i++)
{
if (table.Rows["PHOTO"] != null)
{
fileName = table.Rows["PHOTO"].ToString();
if (RemoteFileExists(webPath + fileName))
{
tem_Dfile = fileName;
tem_Dfile = tem_Dfile.Substring(tem_Dfile.LastIndexOf("/") + 1, tem_Dfile.Length - tem_Dfile.LastIndexOf("/") - 1);
if (Directory.Exists(driveName + "\\gxs\\com.zunran.gxs\\Images") == false)//如果不存在就创建file文件夹
{
Directory.CreateDirectory(driveName + "\\gxs\\com.zunran.gxs\\Images");
}
fileNameTo = driveName + "\\gxs\\com.zunran.gxs\\Images\\" + tem_Dfile;
DownImage(webPath + fileName, fileNameTo);
}
}
}
}
#endregion
//查询数据
if (node_Child.Name == "SELECTSQL")
{
table = esql.ExecuteSelectSQLStr(string.Format(node_Child.InnerText, Model.gXSID));
}
if (node_Child.Name == "INSERTSQL")
{
if (table.Rows.Count > 0)
{
//循环列将列名用,拼接起来在插入数据的时候用
for (int i = 0; i < table.Columns.Count; i++)
{
if (i < table.Columns.Count - 1)
{
columnNames += table.Columns.ColumnName + ",";
}
else if (i == table.Columns.Count - 1)
{
columnNames += table.Columns.ColumnName;
}
}
//遍历每一行数据
try
{
for (int i = 0; i < table.Rows.Count; i++)
{
//将每一行数据的值用,连接起来
for (int j = 0; j < table.Columns.Count; j++)
{
if (j < table.Columns.Count - 1)
{
columnValues += "'" + table.Rows[j] + "'" + ",";
}
else if (j == table.Columns.Count - 1)
{
columnValues += "'" + table.Rows[j] + "'";
}
}
cmd.CommandText = string.Format(node_Child.InnerText, columnNames, columnValues);
SQLiteHelper.ExecuteNonQuery(cmd);
//每插入一条数据就清空一下值
columnValues = "";
}
SQLiteHelper.trans.Commit();
}
catch (Exception e)
{
SQLiteHelper.trans.Rollback();
throw new Exception(e.Message);
}
finally
{
SQLiteHelper.trans = null;
}
//每插入完成一张表清空一下列名
columnNames = "";
}
tableCount += 1;
tableName += node.Name + "\r\n";
//txtNotice.Text = "下载好了" + tableCount.ToString() + "张表中数据";
//解决跨线程给控件赋值的问题
Control.CheckForIllegalCrossThreadCalls = false;
txtNotice.Text = "下载好了下面表\r\n" + tableName + "\r\n共【" + tableCount + "】张表";
}
}
}
}
SQLiteHelper.con.Close();
}
|