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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:11:07+00:00 2026-05-30T15:11:07+00:00

How do i create a file which can store the output info? for example,

  • 0

How do i create a file which can store the output info? for example, i need to get a output where the name repeats 10000 times.. once i stop running the program and start again, it should display the new outputs with the values of the old one.. And if i stop it in between, say 4000th time, it shud start again from 4001 and not all over again.. and how do i use file in this program? could someone help me with the entire program?
The program is –

namespace Time_Writer
{
    class Program
    {
        static int count = 1;
        static double seconds;
        private static System.Timers.Timer aTimer;

        static void Main(string[] args)
        {
            aTimer = new System.Timers.Timer();
            aTimer.Elapsed +=new System.Timers.ElapsedEventHandler(aTimer_Elapsed);
            aTimer.Interval = 5000;
            aTimer.Enabled = true;
            Console.WriteLine("Press Enter To Exit The Program\n");
            Console.ReadLine();

        }
        private static void aTimer_Elapsed(object source, ElapsedEventArgs e)
        {
            Console.WriteLine("Name is Yap {0}", e.SignalTime);
            seconds += 5;
            count += 1;
            if (count>10)
            {
                aTimer.Enabled = false;
                Console.WriteLine("\n\nTimer is off at {0}\n\n", e.SignalTime.TimeOfDay.ToString());
            }
        }


    }
}
  • 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-30T15:11:08+00:00Added an answer on May 30, 2026 at 3:11 pm

    In this example I just save the bits of the count variable to a file in the same directory.

            static void Main(string[] args)
        {
            ReadCountFromFile();
    
            aTimer = new System.Timers.Timer();
            aTimer.Elapsed += new System.Timers.ElapsedEventHandler(aTimer_Elapsed);
            aTimer.Interval = 5000;
            aTimer.Enabled = true;
            Console.WriteLine("Press Enter To Exit The Program\n");
            Console.ReadLine();
    
            AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_DomainUnload);
        }
    
        private static void ReadCountFromFile()
        {
            try
            {
                if (File.Exists(".\\mynumber.dat"))
                {
                    using (var file = File.Open(".\\mynumber.dat", FileMode.Open))
                    {
                        byte[] bytes = new byte[4];
                        file.Read(bytes, 0, 4);
                        count = BitConverter.ToInt32(bytes, 0);
                        Console.WriteLine("Count = {0}", count);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Problem reading file.");
            }
        }
    
        static void CurrentDomain_ProcessExit(object sender, EventArgs e)
        {
            using (var file = File.Open(".\\mynumber.dat", FileMode.OpenOrCreate))
            {
                var buffer = BitConverter.GetBytes(count);
                file.Write(buffer, 0, buffer.Length);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

here i need a batch file which can apply and create label or base
I'm trying to create an object file which can be useable in any computer.
How can I create a simple PHP file, which will retrieve the HTML and
I need to create a batch file which starts multiple console applications in a
I need to create a batch file which will copy web log files from
I wanted to create one js file which includes every js files to attach
I'm looking for a way to (hopefully) create a text file which lists all
I have a row of buttons, which all create a pdf file which I
I would like to create a simple file format/DSL which would allow my users
i would like to set up an external configuration file that I can store

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.