English 中文(简体)
• 如何改变这种单一读写法,使之多读。
原标题:how to modify this single thread into multithreading in c# .net [closed]

要求制定法典的问题必须 尽可能少地理解正在解决的问题。 包括尝试性解决办法,为什么他们做t工作,以及expected 结果。 另见:。 排出问题清单

Closed 10 years ago.

在这里,我想解释一下,如果在A工作完成后,A工作将不去B工作,那么A工作就会长期进行下去,那么现在如何工作,但这里的要求是,所有工作都应启动,但没有任何工作受到侵扰,从而无法改变这种read。

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();
} 
最佳回答

这似乎已经是多方面的。 在每一<代码>的开始和结束时添加伐木法 代号:方法,以便你能够看到四种方法从一起开始并单独停止。

private void FileGenerationForITD()
{
    eventlog1.WriteEntry("FileGenerationForITD started.");
    ...
    eventlog1.WriteEntry("FileGenerationForITD finished.");
}

Additionally, you can knock out all of the if statements. The thread objects are guaranteed to be in that state because nothing changed between new and Start().

Thread threadITD = new Thread(new ThreadStart(FileGenerationForITD));
Thread threadCTD = new Thread(new ThreadStart(FileGenerationForCTD));
// ...
try
{
    ThreadITD.Start();
    ThreadCTD.Start();
    // ...
}

http://www.un.org。 针对评论。

我建议,为了防止时间过长在read子完满之前第二次启动,在时间开始之前,我建议加入read。 <代码>Thread.Join()> 造成这种睡觉,直到参考线索结束为止。 所有其他透镜都是不间断的。

private void CsvGenFromDatabase(object sender, EventArgs e)
{
    timerjob.stop();

    using (TransactionScope scope = new TransactionScope(TransactionScopeOption.RequiresNew))
    {
        Thread threadITD = new Thread(new ThreadStart(FileGenerationForITD));
        Thread threadCTD = new Thread(new ThreadStart(FileGenerationForCTD));
        Thread threadCID = new Thread(new ThreadStart(FileGenerationForCID));
        Thread threadFFM = new Thread(new ThreadStart(FileGenerationForFFM));

        threadITD.Start();
        threadCTD.Start();
        threadCID.Start();
        threadFFM.Start();

        threadITD.Join();
        threadCTD.Join();
        threadCID.Join();
        threadFFM.Join();

        scope.Complete();
    }

    timerjob.start();  
}   
问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...