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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:18:59+00:00 2026-05-20T20:18:59+00:00

I have a class as following public class ScheduledUpdater { private static readonly object

  • 0

I have a class as following

public class ScheduledUpdater
{
    private static readonly object lockingObject = new object();
    private static Queue<int> PendingIDs = new Queue<int>();
    private static bool UpdateThreadRunning = false;
    private static bool IsGetAndSaveScheduledUpdateRunning = false;
    private static DataTable ScheduleConfiguration;
    private static Thread updateRefTableThread;
    private static Thread threadToGetAndSaveScheduledUpdate;
    public static void ProcessScheduledUpdates(int ID)
    {
        //do some stuff
        // if ( updateRefTableThread not already running)
        // execute updateRefTableThread = new Thread(new ThreadStart(UpdateSchedulingRefTableInThrear));
        // execute updateRefTableThread.Start();
        //do  some stuff
        ***[1]***
        GetAndSaveScheduledUpdate(ID)
    }
    private static void UpdateSchedulingRefTableInThrear()
    {
        //if(updateRefTableThread==true)
        //    return;
        // updateRefTableThread = true
        do{
        UpdateSchedulingRefTable(); 
        Thread.sleep(800000);
        }while(updateRefTableThread);
        //updateRefTableThread = false;
    }
    public static void UpdateSchedulingRefTable()
    { 
        // read DB and update ScheduleConfiguration 
        string query = " SELECT ID,TimeToSendEmail FROM TBLa WHERE MODE = 'WebServiceOrder' AND BDELETE = false ";
        clsCommandBuilder commandBuilder = new clsCommandBuilder();
        DataSet ds = commandBuilder.GetDataSet(query);
        if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
        {
            List<string> lstIDs = new List<string>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                lstIDs.Add(ds.Tables[0].Rows[i]["ID"].ToString());
                if (LastEmailSend.Contains(ds.Tables[0].Rows[i]["ID"].ToString()))
                    LastEmailSend[ds.Tables[0].Rows[i]["ID"].ToString()] = ds.Tables[0].Rows[i]["TimeToSendEmail"].ToString();
                else
                    LastEmailSend.Add(ds.Tables[0].Rows[i]["ID"].ToString(), ds.Tables[0].Rows[i]["TimeToSendEmail"].ToString());
            }
            if (lstIDs.Count > 0)
            {
                string Ids = string.Join(",", lstIDs.ToArray()).Trim(',');
                dhDBNames dbNames = new dhDBNames();
                dbNames.Default_DB_Name = dbNames.ControlDB;
                dhGeneralPurpose dhGeneral = new dhGeneralPurpose();
                dhGeneral.StringDH = Ids;
                DataSet result = commandBuilder.GetDataSet(dbNames, (object)dhGeneral, "xmlGetConfigurations");
                if (result != null && result.Tables.Count > 0)
                {
                    ***[2]***
                    Monitor.Enter(lockingObject);
                    if (ScheduleConfiguration != null)
                        ScheduleConfiguration.Clear();
                    ScheduleConfiguration = result.Tables[0];
                    Monitor.Exit(lockingObject);
                }
            }
        }
    }
    public static void GetAndSaveScheduledUpdate(int ID)
    {
        ***[3]***
        //use ScheduleConfiguration 
        Monitor.Enter(lockingObject);
        if (ScheduleConfiguration == null)
        {
            UpdateSchedulingRefTable();
            Monitor.Exit(lockingObject);

        }
        else
            Monitor.Exit(lockingObject);
        Monitor.Enter(lockingObject);
        DataRow[] result = ScheduleConfiguration.Select("ID = "+ID);
        Monitor.Exit(lockingObject);
        //then for each result row, i add this to a static Queue PendingIDs

    }
}

The function UpdateSchedulingRefTable can be called any time from outside world (for instance if someone updates the schedule configuration manually)
ProcessScheduledUpdates is called from a windows service every other minute.
Problem:
Datatable ScheduleConfiguration is updated in the UpdateSchedulingRefTable (called from outside world – say manually) but when i try to use Datatable ScheduleConfiguration in GetAndSaveScheduledUpdate, i get the older version of values….

What am I missing in this stuff???

About EDIT: I thought the stuff i have not shown is quite obvious and possibly not desired, perhaps my structure is wrong 🙂 and sorry for incorrect code previously, i made a simple function call as a thread initialization… sorry for my code indentation too because i don’t know how to format whole block…

Edit 2: ProcessScheduledUpdates is called from a windows service (say every second).
I am first hitting point [1] (it will automatically hit point [2] and update ScheduleConfiguration), then i manually update DB and hit point [2]. Then i hit point [1] again to just check the status
My problem is now, that i get two entirely different copies of ScheduleConfiguration at point [1] and [2].

Edit 3 I think my question is invalid; i wanted to share data betweena a windows form click and a windows service. No matter how many shared things i have, atleast the address space will be different… My bad…

  • 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-20T20:19:00+00:00Added an answer on May 20, 2026 at 8:19 pm

    Well, for one thing there’s no sign that you’ve got any memory barriers anywhere which would ensure that any writes are fully “flushed” to main memory, and that reads go to main memory instead of using registers etc. Basically you shouldn’t use fields shared between threads without some sort of protection.

    Now that’s a theoretical risk to some extent – it’s not clear that that’s actually the problem, although it’s certainly a real possibility. I strongly suspect there’s another problem, but in the code that you haven’t shown us. Do you have diagnostics to indicate that the first thread definitely wrote to ScheduleConfiguration?

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

Sidebar

Related Questions

So I have the following: public class Singleton { private Singleton(){} public static readonly
I have a class like following: public class Trainee { private static int numberOfTrainee
I have following class public class ButtonChange { private int _buttonState; public void SetButtonState(int
I have the following class [DataContract] public class A { private List<B> b= new
I have following class: public class PairOfDice { private Dice d1,d2; public int Value
I have the following class: public abstract class AbstractParent { static String method() {
Suppose I have the following class: public class TestBase { public bool runMethod1 {
Let's say I have the following class: public class Test<E> { public boolean sameClassAs(Object
I have the following class objects: public class VacancyCategory { public int ID {
I have a class that looks like the following: public class MyClass { private

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.