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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:50:48+00:00 2026-05-18T22:50:48+00:00

http://www.codeproject.com/KB/threads/winformsthreading.aspx I’m attempting to use the above, and while it works in some sense

  • 0

http://www.codeproject.com/KB/threads/winformsthreading.aspx

I’m attempting to use the above, and while it works in some sense (it doesn’t lock up my application), it isn’t updating the labels on the UI unfortunately. Am I going wrong somewhere? I have two labels that are on the MainForm, expiredPoliciesLabel and missingPoliciesLabel. To update them, I have to set expiredPoliciesNum and missingPoliciesNum by doing a series of database queries, as you can see. I need the labels to update automatically every minute or so. (I know right now I have it set at 1 second, it’s only to see if the code is working)

Here is my code.

public delegate void updatePolicyLabelsDelegate();

public partial class MainForm: Form
{
    SQLiteQuery sqliteQuery = new SQLiteQuery(Properties.Settings.Default.DatabasePath);
    int expiredPoliciesNum = 0;
    int missingPoliciesNum = 0;
    Thread minimizeThread;

    public MainForm()
    {
        this.Resize += new EventHandler(MainForm_Resize);
        this.IsMdiContainer = true;
        InitializeComponent();
        this.ShowInTaskbar = false;

        keyValidation();

        Thread bottomLabelsThread = new Thread(new ThreadStart(updateLabels));
        bottomLabelsThread.IsBackground = true;
    }

    public void updateLabels()
    {
        while (true)
        {
            Invoke(new updatePolicyLabelsDelegate(updatePolicyLabels));
            Thread.Sleep(1000);
        }
    }

    private void updatePolicyLabels()
    {
        DataTable dt = sqliteQuery.selectFromDatabase("*", "WHERE GLOPolicy != '1'");
        missingPoliciesNum = dt.Rows.Count;

        dt = sqliteQuery.selectFromDatabase("*", "WHERE ALPolicy != '1'");
        missingPoliciesNum = missingPoliciesNum + dt.Rows.Count;

        dt = sqliteQuery.selectFromDatabase("*", "WHERE WCPolicy != '1'");
        missingPoliciesNum = missingPoliciesNum + dt.Rows.Count;

        dt = sqliteQuery.selectFromDatabase("*", "WHERE ULPolicy != '1'");
        missingPoliciesNum = missingPoliciesNum + dt.Rows.Count;

        String now = DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day;

        dt = sqliteQuery.selectFromDatabase("*", "WHERE GLOPolicy = '1' AND GLOExpiration < '" + now + "'");
        expiredPoliciesNum = dt.Rows.Count;

        dt = sqliteQuery.selectFromDatabase("*", "WHERE ALPolicy = '1' AND ALExpiration < '" + now + "'");
        expiredPoliciesNum = expiredPoliciesNum + dt.Rows.Count;

        dt = sqliteQuery.selectFromDatabase("*", "WHERE WCPolicy = '1' AND WCExpiration < '" + now + "'");
        expiredPoliciesNum = expiredPoliciesNum + dt.Rows.Count;

        dt = sqliteQuery.selectFromDatabase("*", "WHERE ULPolicy = '1' AND ULExpiration < '" + now + "'");
        expiredPoliciesNum = expiredPoliciesNum + dt.Rows.Count;


        expiredPoliciesLabel.Text = expiredPoliciesNum + " Expired Policies       ";
        missingPoliciesLabel.Text = missingPoliciesNum + " Missing Policies       ";
    }

Thanks for any help, I’m new to threading, and could use some expertise, and believe it or not, I’ve searched everywhere trying to figure out where I’m going wrong to no avail.

  • 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-18T22:50:49+00:00Added an answer on May 18, 2026 at 10:50 pm

    You created the thread object, but you don’t start it, as your code seems to show:

    bottomLabelsThread.Start();
    

    It is not started automatically.

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

Sidebar

Related Questions

I use 2 threads to act like a produce/consumer using double queue ( http://www.codeproject.com/KB/threads/DoubleQueue.aspx
I spot some interesting articles about exception handle in CodeProject http://www.codeproject.com/KB/cpp/seexception.aspx After reading, I
I want to use virtual keyboard assembly found here http://www.codeproject.com/KB/miscctrl/touchscreenkeyboard.aspx like on screen keyboard
i am using this code for suspend process.i found it here http://www.codeproject.com/KB/threads/pausep.aspx BOOL SuspendResumeThreadList(DWORD
I have to use this external functions GetOpenedFiles (more info to: http://www.codeproject.com/KB/shell/OpenedFileFinder.aspx ) into
I'm implementing localization in my WCF application according to http://www.codeproject.com/KB/WCF/WSI18N.aspx and some other articles.
Hello I managed to use the class ClassWSThumb (you can find it here http://www.codeproject.com/KB/aspnet/Website_URL_Screenshot.aspx
I'm following the example here : http://www.codeproject.com/KB/aspnet/BilingualMvc3Part2.aspx Edit: This solution works for Firefox, and
I came accross this: http://www.codeproject.com/KB/tips/SerializedObjectCloner.aspx and would like to use it to deep copy
I'm attempting my first SSO integration using SAML 2.0. I've been using: http://www.codeproject.com/KB/aspnet/DotNetSamlPost.aspx?msg=3562384 as

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.