Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7082285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:01:45+00:00 2026-05-28T07:01:45+00:00

hi here am using single threading in c#.net, let me explain you how it

  • 0

hi here am using single threading in c#.net, let me explain you how it is working now if suppose job A is running in a long process until unless it job A was completed it will not go for job B, but here requirement is all the jobs should gets activated but none of the jobs get intrupted so how can i modify this threading, can any give some suggestions please asap

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();
} 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:01:45+00:00Added an answer on May 28, 2026 at 7:01 am

    This appears to already be multi-threaded. Try adding logging code to the start and end of each FileGenerationForXXX method so you can see the four methods starting together and stopping separately.

    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();
        // ...
    }
    

    EDIT: In response to comments.

    To prevent the timer from triggering a second time before the threads all complete, I suggest joining the threads before starting the timer again. Thread.Join() causes this thread to sleep until the referenced thread has ended. All other threads contiunue uninterrupted.

    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();  
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Are there any race condition issues when using NSNotifications within a single thread? Here
Anybody tried here using Getting Real(37Signals) approach to develop windows application? (C#/.NET). Or simply
Who here is using WASP ( http://wasp.sourceforge.net/content/ ) to in real world applications? What
I'm setting up a net.tcp WCF service using instructions here: http://blogs.msdn.com/swiss_dpe_team/archive/2008/02/08/iis-7-support-for-non-http-protocols.aspx One of the
I found an example here of using rounded corners using a single image. I've
I have read the post here about using setTimeout() during intensive DOM processing (using
Using Rational ClearCase v. 7.0.1.1 with UCM, I have a problem here when using
what is the value of using IDictionary here?
Probably not much more to elaborate on here - I'm using a NumericStepper control
I call a javascript function from a textbox by using OnKeyPress=clickSearchButton() Here is my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.