public void GenerateData(string dbFullName)
{
bool bSuccess = true;
if (File.Exists(dbFullName))
{
File.Delete(dbFullName);
}
System.Data.SQLite.SQLiteConnection.CreateFile(dbFullName);
if (File.Exists(dbFullName))
{
SQLiteHelper.connectionString = SQLiteHelper.GetConn(dbFullName);
bSuccess = SQLiteHelper.InitGenerateDB(new string[] {
CommonGenerateData.CreateBuildingType,
CommonGenerateData.CreateLocationBasicInfo,
CommonGenerateData.CreateLocationOtherInfo,
CommonGenerateData.CreateEleLocation,
CommonGenerateData.CreateEleLocationPct,
CommonGenerateData.CreateLocationAttach,
CommonGenerateData.CreateElection });
using (SQLiteConnection sqliteConn = new SQLiteConnection(SQLiteHelper.connectionString))
{
sqliteConn.Open();
List<Action<SQLiteTransaction>> delegetlist = new List<Action<SQLiteTransaction>>() {
CommonGenerateData.GenerateBuildingType,
CommonGenerateData.GenerateLocationBasicInfo,
CommonGenerateData.GenerateLocationOtherInfo,
CommonGenerateData.GenerateEleLocation,
CommonGenerateData.GenerateEleLocationPct,
CommonGenerateData.GenerateLocationAttach,
CommonGenerateData.GenerateElection
};
WaitHandle[] waitHandles = new WaitHandle[]{
new AutoResetEvent(false),
new AutoResetEvent(false),
new AutoResetEvent(false),
new AutoResetEvent(false),
new AutoResetEvent(false),
new AutoResetEvent(false),
new AutoResetEvent(false)
};
using (SQLiteTransaction tran = sqliteConn.BeginTransaction())
{
for (int i = 0; i < delegetlist.Count; i++)
{
Action<SQLiteTransaction> deleget = delegetlist[i];
AutoResetEvent resetEvent = (AutoResetEvent)waitHandles[i];
ThreadPool.QueueUserWorkItem(stateInfo => {
deleget(tran);
resetEvent.Set();
}, waitHandles[i]);
}
WaitHandle.WaitAll(waitHandles);
tran.Commit();
}
sqliteConn.Close();
}
}
}