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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:47:28+00:00 2026-06-13T22:47:28+00:00

Morning all, Using C# .NET 4.0 and Visual Studio 2012 Express. I have a

  • 0

Morning all,

Using C# .NET 4.0 and Visual Studio 2012 Express.

I have a program that runs some SQL stored procedures, then opens and Access database and auto generates the reports then emails them.

I have it set on a date so it runs as soon as midnight comes.

The following is a code sample.

private void button1_Click(object sender, EventArgs e)
{
    Thread myUltiThread = new Thread(GetCurrentDate);
    myUltiThread.Start();
}

private void GetCurrentDate()
{
    string myDate = "";
    myDate = DateTime.Today.Day.ToString();

    if(myDate == "7" && myDateToggle == false)
    {
        Task t = new Task(() => RunMonthBackUp());
        t.Start();
    }

    if (myDate == "8" && myDateToggle == true)
    {
        myDateToggle = false;
    }
}

So as you can see once the button is pressed my program then starts the thread, which uses the getdate method, this method checks if the date is correct.

if it is then it starts a task that runs the whole process.

My problem is that this is not happening, I believe its because the method is only running once. I have a feeling this is due to my lack of understanding working with threads (only ever deal with tasks usually).

Could someone point out to me where I am going wrong and how to get this set up properly?

Many thanks guys

  • 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-06-13T22:47:29+00:00Added an answer on June 13, 2026 at 10:47 pm

    Your thread will be terminated when GetCurrentDate method reaches the end. You should provide a loop in your method and check for the condition periodically. Or you can set a timer (System.Threading.Timer) to check periodically for the condition.

    Here is the first way:

    private void button1_Click(object sender, EventArgs e)
    {
        Thread myUltiThread = new Thread(GetCurrentDate);
        myUltiThread.IsBackground = true;
        myUltiThread.Start();
    }
    
    private void GetCurrentDate()
    {
        while(true)
        {
            int = DateTime.Today.Day;
    
            if(myDate == 7 && myDateToggle == false)
            {
                Task t = new Task(() => RunMonthBackUp());
                t.Start();
            }
    
            if (myDate == 8 && myDateToggle == true)
            {
                myDateToggle = false;
            }
    
            Thread.Sleep(1);
        }
    }
    

    I also made the thread a background thread, so you don’t need to worry about terminating the thread. The thread will continue to function until the program exits.

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

Sidebar

Related Questions

Good Morning All. I have a table structure (I am using SQL SERVER 2000)
Morning All, I have a form that I am using to add multiple rows
Good Morning All, I have code similar to the following try{ using(var tx =
We are using ASP.NET MVC with LINQ to SQL. We added some features and
Good Morning All! I have been developing a project for some time in which
I have been racking my brain all morning with this. I am using Eclipse
Good evening/morning/after/noon. I have an ASP.net 3.5 website and I am using vb.net in
Good evening/morning/after/noon. I have an ASP.net 3.5 website and I am using vb.net in
Morning All, Previously I have been using $(#WebPartWPQ2 .ms-formtable tr:contains('lblName')> td).toggleClass('changedetails'); to customise a
Good morning all, I'm having some issues with floating point math, and have gotten

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.