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 679285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:14:35+00:00 2026-05-14T01:14:35+00:00

I am using the console application i used multi threading in the same. I

  • 0

I am using the console application i used multi threading in the same. I just want to know which section have to put inside critical section my code is :
.——————————————————————————.
public class SendBusReachSMS
{

    public void SchedularEntryPoint()
    {
        try
        {
            List<ActiveBusAndItsPathInfo> ActiveBusAndItsPathInfoList = BusinessLayer.GetActiveBusAndItsPathInfoList();
            if (ActiveBusAndItsPathInfoList != null)
            {
                //SMSThreadEntryPoint smsentrypoint = new SMSThreadEntryPoint();
                while (true)
                {
                    foreach (ActiveBusAndItsPathInfo ActiveBusAndItsPathInfoObj in ActiveBusAndItsPathInfoList)
                    {
                        if (ActiveBusAndItsPathInfoObj.isSMSThreadActive == false)
                        {

                            DateTime CurrentTime = System.DateTime.Now;
                            DateTime Bustime = Convert.ToDateTime(ActiveBusAndItsPathInfoObj.busObj.Timing);
                            TimeSpan tsa = Bustime - CurrentTime;

                            if (tsa.TotalMinutes > 0 && tsa.TotalMinutes < 5)
                            {
                                ThreadStart starter = delegate { SMSThreadEntryPointFunction(ActiveBusAndItsPathInfoObj); };
                                Thread t = new Thread(starter);
                                t.Start();
                                 t.Join();
                            }
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine("===========================================");
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.InnerException);
            Console.WriteLine("===========================================");
        }
    }


    public void SMSThreadEntryPointFunction(ActiveBusAndItsPathInfo objActiveBusAndItsPathInfo)
    {
        try
        {
            //mutThrd.WaitOne();
            String consoleString = "Thread for " + objActiveBusAndItsPathInfo.busObj.Number + "\t" + " on path " + "\t" + objActiveBusAndItsPathInfo.pathObj.PathId;
            Console.WriteLine(consoleString);
            TrackingInfo trackingObj = new TrackingInfo();
            string strTempBusTime = objActiveBusAndItsPathInfo.busObj.Timing;
            while (true)
            {

                trackingObj = BusinessLayer.get_TrackingInfoForSendingSMS(objActiveBusAndItsPathInfo.busObj.Number);

                if (trackingObj.latitude != 0.0 && trackingObj.longitude != 0.0)
                {
                    //calculate distance
                    double distanceOfCurrentToDestination = 4.45;
                    TimeSpan CurrentTime = System.DateTime.Now.TimeOfDay;
                    TimeSpan timeLimit = objActiveBusAndItsPathInfo.sessionInTime - CurrentTime;
                    if ((distanceOfCurrentToDestination <= 5) && (timeLimit.TotalMinutes <= 5))
                    {
                        Console.WriteLine("Message sent to bus number's parents: " + objActiveBusAndItsPathInfo.busObj.Number);
                        break;
                    }
                }
            }
           // mutThrd.ReleaseMutex();
        }
        catch (Exception ex)
        {
            //throw;
            Console.WriteLine("===========================================");
            Console.WriteLine(ex.Message);
            Console.WriteLine(ex.InnerException);
            Console.WriteLine("===========================================");
        }

    }

}

Please help me in multithreading. new topic for me in .net

  • 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-14T01:14:35+00:00Added an answer on May 14, 2026 at 1:14 am

    Generally you have to identify the objects that are shared between threads. That is obviously objActiveBusAndItsPathInfo. You have potential problem if two threads get the instance of the same object, and modification of property of this shared object on 1st thread can affect the behaviour of the 2nd thread. But looking at SMSThreadEntryPointFunction I see no such danger, assuming that number is passed to get_TrackingInfoForSendingSMS as value (or I have overlooked something).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 388k
  • Answers 388k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I'm not sure it's possible to control the cursor, but… May 15, 2026 at 12:29 am
  • Editorial Team
    Editorial Team added an answer For the "what am I doing wrong?" part...there is no… May 15, 2026 at 12:29 am
  • Editorial Team
    Editorial Team added an answer I played with the previously offered solution but still had… May 15, 2026 at 12:29 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.