ここでは、ジョブA以外の長いプロセスでジョブAが実行されていると仮定した場合の、C#.netのシングルスレッド化の使用方法を説明します。完成したいずれかのいくつかの提案は、できるだけ早くc#.netでこの単一のスレッドをマルチスレッド化する方法
protected override void OnStart(string[] args)
{
strNowDate = DateTime.Now.ToLongTimeString();
timerjob.Elapsed += new ElapsedEventHandler(CsvGenFromDatabase);
timerjob.Interval = Convert.ToDouble(DueTime);
timerjob.Enabled = true;
eventLog1.WriteEntry("my service started");
}
protected override void OnStop()
{
strNowDate = DateTime.Now.ToLongTimeString();
eventLog1.WriteEntry("my service stopped");
}
private void CsvGenFromDatabase(object sender, EventArgs e)
{
timerjob.stop();
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew)) // Transaction Scope Started
{
Thread threadITD = new Thread(new ThreadStart(FileGenerationForITD)); // Thread Initialize for ITD
Thread threadCTD = new Thread(new ThreadStart(FileGenerationForCTD)); // Thread Initialize for CTD
Thread threadCID = new Thread(new ThreadStart(FileGenerationForCID)); // Thread Initialize for CID
Thread threadFFM = new Thread(new ThreadStart(FileGenerationForFFM)); // Thread Initialize for FFM
try
{
if ((threadITD == null) ||
(threadITD.ThreadState == System.Threading.ThreadState.Stopped) ||
(threadITD.ThreadState == System.Threading.ThreadState.Unstarted))
{
threadITD.Start(); // Thread Started for ITD
}
if ((threadCTD == null) ||
(threadCTD.ThreadState == System.Threading.ThreadState.Stopped) ||
(threadCTD.ThreadState == System.Threading.ThreadState.Unstarted))
{
threadCTD.Start(); // Thread Started for CTD
}
if ((threadCID == null) ||
(threadCID.ThreadState == System.Threading.ThreadState.Stopped) ||
(threadCID.ThreadState == System.Threading.ThreadState.Unstarted))
{
threadCID.Start(); // Thread Started for CID
}
if ((threadFFM == null) ||
(threadFFM.ThreadState == System.Threading.ThreadState.Stopped) ||
(threadFFM.ThreadState == System.Threading.ThreadState.Unstarted))
{
threadFFM.Start(); // Thread Started for FFM
}
}
catch (Exception ex)
{
objErrorLog.SrtErrorText = ex.ToString().Substring(0, 25);
objErrorLog.StrErrorDescription = ex.ToString();
objErrorLog.WriteErrorLog(objErrorLog);
}
finally
{
scope.Complete();
}
}
timerjob.start();
}
@MitchWheat - M.Babcock @ –
が親切マルチスレッディングにとして変更のためにそれを私を助けて...ということができるすべては、私はこのウィンドウサービス – pravz
@pravzに新しいですされる - これが唯一のですがあなたが投稿したコードの多くの明らかな問題の1つ、[BackgroundWorker](http://www.dreamincode.net/forums/topic/112547-using-the-backgroundworker-in-c%23/)にあなたを紹介しましょう。 )。 –