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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:52:13+00:00 2026-06-05T13:52:13+00:00

I have created a console application in C# and there is main method (static)

  • 0

I have created a console application in C# and there is main method (static) and my requirement is to initialize 2 timers and handles 2 methods respectively which will be called periodically to do some task. Now I have taken all other methods/variables static because that are calling from timer handler events (which are static due to calling it from main).

Now i would like to know for above scenario how memory is going to be consumed if this console running for long time? if i would like to apply oops concept then do i need make all methods/variables non static and access that by creating object of class? in this case how memory going to be consume?

Update:
Following is snippet of my code

 public class Program
    {
        readonly static Timer timer = new Timer();
        static DateTime currentDateTime;
        //other static variables
        //-----
        static void Main()
        {
            timer.Interval = 1000 * 5;
            timer.AutoReset = true;
            timer.Enabled = true;
            timer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            timer.Start();

            //2nd timer
            //-----

            System.Console.ReadKey();
            timer.Stop();
        }

        static void timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            currentDateTime = DateTime.UtcNow;
            PushData();

        }

        private static void PushData()
        {
            //Code to push data
        }
    }
  • 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-05T13:52:16+00:00Added an answer on June 5, 2026 at 1:52 pm

    You shouldn’t be deciding whether or not to use static fields/methods based on memory consumption (which likely won’t be altered much). Instead, you should go with what produces cleaner, more testable code.

    Static methods are okay (IMO) if you don’t need any kind of polymorphic behaviour, and if the method doesn’t logically act on an instance of the type. However, if you’ve also got static variables involved, that’s more of an issue. Static variables – other than constants – can make code much harder to test, reuse, and handle correctly in multiple threads.

    It sounds like you probably should be using instance variables and methods. Just make your Main method create an instance of the class, and it can use that instance to create delegates to pass to the timer. It’s hard to be much more precise than that without knowing more about what you’re doing, but it does sound like you’re using statics for immediate convenience rather than because it’s the right thing to do, which is always a worry.

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

Sidebar

Related Questions

I have created a small chatting application in C#, and started as a Console
I have a console application from which I create a window. I can render
I have the following console application written in VB.NET: Sub Main() Dim ie As
I am writing a web application and there I have created a class with
I have created the following test program: static void Main(string[] args) { using (var
i have created a very simple console application in vb.net that emails me some
I have written a little console application that uses s#arp. I can create an
I have created a bar chart which is a improvement of bar graph on
Hey there. I have a c# application that parses txt files and imports the
I'm writing a console application which is looking up information about SSIS packages in

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.