本文共 2946 字,大约阅读时间需要 9 分钟。
添加一个的webservice引用
using System; using System.Collections.Generic; using System.Text; using System.Threading; using System.Data; using System.Data.SQLite; namespace GetMobileData{ class GetData{ public void Get(){ for ( int i = 0 ; i <= 9 ; i ++ ){ new Thread( new ParameterizedThreadStart(GetThread)).Start(i);} // List<MobileInfo> mInfos = new List<MobileInfo>(); } private void GetThread( object obj){ int nMobileBase = 1300001 ; int nOffset = 1300000 ; int i = ( int )obj;nMobileBase += i * 10000 ;nOffset += i * 10000 + 9999 ; for ( int j = nMobileBase; j < nOffset; j ++ ){ MobileInfo mInfo = new MobileInfo();mInfo.MobileCode = j.ToString();MobileService.Mobile mobileSrv = new MobileService.Mobile();Console.WriteLine( " 正在查询 " + j);mobileSrv.Query(j.ToString() + 1234 , out mInfo.Province, out mInfo.City, out mInfo.AreaCode, out mInfo.PostCode, out mInfo.CorpName, out mInfo.CardName);Console.WriteLine( " 正在保存 " + j);SaveToDB(mInfo);}} private void SaveToDB(MobileInfo mInfo){ SQLiteConnection liteConn = new SQLiteConnection( " Data Source=E:\\UtilData\\mobile;Version=3;New=True; " );liteConn.Open(); string sSql = " INSERT INTO m_mobile_data (cMobileCode,cProvince,cCity,cAreaCode,cPostCode,cCorpName,cCardName) " + " VALUES(@MobileCode,@Province,@City,@AreaCode,@PostCode,@CorpName,@CardName) " ;SQLiteCommand liteCmd = new SQLiteCommand(liteConn);liteCmd.CommandText = sSql; // liteCmd.Parameters. SQLiteParameter litePara = new SQLiteParameter();litePara.ParameterName = " MobileCode " ;litePara.DbType = DbType.String;litePara.Value = mInfo.MobileCode;liteCmd.Parameters.Add(litePara);litePara = new SQLiteParameter();litePara.ParameterName = " Province " ;litePara.DbType = DbType.String;litePara.Value = mInfo.Province;liteCmd.Parameters.Add(litePara);litePara = new SQLiteParameter();litePara.ParameterName = " City " ;litePara.DbType = DbType.String;litePara.Value = mInfo.City;liteCmd.Parameters.Add(litePara);litePara = new SQLiteParameter();litePara.ParameterName = " AreaCode " ;litePara.DbType = DbType.String;litePara.Value = mInfo.AreaCode;liteCmd.Parameters.Add(litePara);litePara = new SQLiteParameter();litePara.ParameterName = " PostCode " ;litePara.DbType = DbType.String;litePara.Value = mInfo.PostCode;liteCmd.Parameters.Add(litePara);litePara = new SQLiteParameter();litePara.ParameterName = " CorpName " ;litePara.DbType = DbType.String;litePara.Value = mInfo.CorpName;liteCmd.Parameters.Add(litePara);litePara = new SQLiteParameter();litePara.ParameterName = " CardName " ;litePara.DbType = DbType.String;litePara.Value = mInfo.CardName;liteCmd.Parameters.Add(litePara);liteCmd.ExecuteNonQuery();liteConn.Close();}} class MobileInfo{ public string MobileCode; public string Province; public string City; public string AreaCode; public string PostCode; public string CorpName; public string CardName;}} 打算在PSP上做应用
所以使用的sqlite.
开了10个线程,暂时先跑130到139段
转载地址:http://dalgb.baihongyu.com/