在Program.cs中,我有下面的方法檢查和同步中央服務器的SQL數據庫。每個人都與另一個人分開,所以我想通過讓他們同時運行來加快程序的加載時間。背景工作者是否有限制?技術或常識
不幸的是,它是非常片狀的工作,然後不是下一個。本地數據庫是SQLExpress 2005,中央數據庫是SQL Server Standard 2005.
這些數據庫中有多少個連接可以有限制?如果背景工作者,我能一次只有這麼多運行嗎?我確信有這樣一個更有說服力的方法,我很樂意聽到(看)他們。
這是我在main()在Program.cs中調用這個 - >
if(IsSqlAvailable()) SyncNow();
internal static void SyncNow()
{
#region ConnectDB Merge Sync Background Thread
BackgroundWorker connectBW = new BackgroundWorker
{
WorkerReportsProgress = false,
WorkerSupportsCancellation = true
};
connectBW.DoWork += new DoWorkEventHandler(connectBW_DoWork);
if (connectBW.IsBusy != true)
connectBW.RunWorkerAsync();
#endregion
#region aspnetDB Merge Sync Background Thread
BackgroundWorker aspBW = new BackgroundWorker
{
WorkerReportsProgress = false,
WorkerSupportsCancellation = true
};
aspBW.DoWork += new DoWorkEventHandler(aspBW_DoWork);
if (aspBW.IsBusy != true)
aspBW.RunWorkerAsync();
#endregion
#region MatrixDB Merge Sync Background Thread
BackgroundWorker matrixBW = new BackgroundWorker
{
WorkerReportsProgress = false,
WorkerSupportsCancellation = true
};
matrixBW.DoWork += new DoWorkEventHandler(matrixBW_DoWork);
if (matrixBW.IsBusy != true)
matrixBW.RunWorkerAsync();
#endregion
#region CMODB Merge Sync Background Thread
BackgroundWorker cmoBW = new BackgroundWorker
{
WorkerReportsProgress = false,
WorkerSupportsCancellation = true
};
cmoBW.DoWork += new DoWorkEventHandler(cmoBW_DoWork);
if (cmoBW.IsBusy != true)
cmoBW.RunWorkerAsync();
#endregion
#region MemberCenteredPlanDB Merge Sync Background Thread
BackgroundWorker mcpBW = new BackgroundWorker
{
WorkerReportsProgress = false,
WorkerSupportsCancellation = true
};
mcpBW.DoWork += new DoWorkEventHandler(mcpBW_DoWork);
if (mcpBW.IsBusy != true)
mcpBW.RunWorkerAsync();
#endregion
}
static void mcpBW_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
try
{
MergeRepl mcpMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "MemberCenteredPlan", "MemberCenteredPlan", "MemberCenteredPlan");
mcpMergeRepl.RunDataSync();
areAllInSync += 1;
}
catch (Exception)
{
if (worker != null) worker.CancelAsync();
}
}
static void cmoBW_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
try
{
MergeRepl cmoMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "CMO", "CMO", "CMO");
cmoMergeRepl.RunDataSync();
areAllInSync += 1;
}
catch (Exception)
{
if (worker != null) worker.CancelAsync();
}
}
static void connectBW_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
try
{
MergeRepl connectMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "CONNECT", "Connect", "Connect");
connectMergeRepl.RunDataSync();
areAllInSync += 1;
}
catch (Exception)
{
if (worker != null) worker.CancelAsync();
}
}
static void matrixBW_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
try
{
MergeRepl matrixMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "MATRIX", "MATRIX", "MATRIX");
matrixMergeRepl.RunDataSync();
areAllInSync += 1;
}
catch (Exception)
{
if (worker != null) worker.CancelAsync();
}
}
static void aspBW_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
try
{
MergeRepl aspnetdbMergeRepl = new MergeRepl(SystemInformation.ComputerName + "\\SQLEXPRESS", "WWCSTAGE", "aspnetdb", "aspnetdb", "aspnetdb");
aspnetdbMergeRepl.RunDataSync();
areAllInSync += 1;
}
catch (Exception)
{
if (worker != null) worker.CancelAsync();
}
}
對於初學者,我發現我的While是EVIL並導致了一些問題。 – 2009-07-15 20:58:51