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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:51:34+00:00 2026-06-07T17:51:34+00:00

How can we remove a piece of code from a application after a number

  • 0

How can we remove a piece of code from a application after a number of execution? Let me give an example, right now, I have this application SomeSoftware, that takes backup of data every month or so. What it does is, that at the time of installation on client’s machine (on deployment) it creates an entry in database about the date it was installed on, and then at each run it checks something like

var con = InitializeDB.StartConnection(); // start the connection
var cmd = con.CreateCommand();
var cmdOther = con.CreateCommand();
// check if its the first run of the software
#region onlyUsefulForFirstTime
cmd.CommandText = "SELECT Count(*) FROM Misc WHERE ItemName='FirstRun'"
if (Int32.Parse(cmd.ExecuteScalar().ToString()) == 0)
    // it is the first run, add the entry
    cmd.CommandText = "INSERT INTO Misc(ItemName, Val) VALUES('FirstRun'," +  DateTime.Now + ")";
else
#endregion
    // it is not the first run
    cmd.CommandText = "SELECT Val FROM Misc WHERE ItemName='LastRun'";
    cmdOther.CommandText = "SELECT Val FROM Misc WHERE ItemName='FirstRun'";
    // now after this, we compare the value of LastRun and the date in FirstRun, if it's more than a month, we take the steps to backup the database

what’s happening currently is that at each start up of the application, it is executing the code inside region onlyUsefulForFirstTime, though its only useful for first time run. If client were to run this application 10 times in a day, it would be a total waste to keep letting this code execute. I know, I need to check somewhere if its first run or not, so to add the value, but after that its just waste. So, is there any way I could remove this code, and not exactly remove, but make the code in onlyUsefulForFirstTime not execute again, or something like that, well! you get the idea!

ps : I am not asking about other methods for backup or other strategy to backup, I know there are others, but that’s not the question!

  • 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-07T17:51:36+00:00Added an answer on June 7, 2026 at 5:51 pm

    Add a key to the Windows registry, indicating that the code has already run. Check this registry key on startup of your application.

    Alternatively, you can use an application setting:

    if (Properties.Settings.Default.alreadyExecuted == false)
    {
         // run one-time code.
    
         Properties.Settings.Default.alreadyExecuted = true;
         Properties.Settings.Default.Save();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

You have some code you want to remove associated with an obsolete piece of
I have the following piece of code: string root = Path.GetDirectoryName(Application.ExecutablePath); List<string> FullFileList =
we can remove formula from one cell by cell.setCellFormula(null) . but if i want
How we can remove an array entry from : var a = [],b =
How to I can remove posts from a specific category from homepages in wordpress?
i have the following piece of code my my web.config: <customErrors mode=On defaultRedirect=~/Exception.aspx enableVersionHeader=false>
I have spent hours trying to get my head around a piece of code
I have this little piece of jQuery/jqModal code which works fine. However, I am
I have a div that has inside a piece of php code I need
I have the following piece of code: public class DumpLocationLog extends Thread { LocationManager

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.