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

  • Home
  • SEARCH
  • 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 6566745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:15:08+00:00 2026-05-25T14:15:08+00:00

ok so ive been working on a program. i has 3 classes. 2 of

  • 0

ok so ive been working on a program. i has 3 classes. 2 of the classes have timers that repeat at different intervals and once one “cycle” of the timer is done it raises an event with a string as return. the 3rd class subscribes to the events from the other two timer classes and does something with teh strings like print to console.

but i cant get it to work, it compiles fine but it just opens a console and then closes it fast(with no output). do you guys see anything wrong?

thanks

CODE:

using System;
using System.Timers;
using System.Text;
using System.Xml;
using System.IO;
using System.IO.Ports;
using System.IO.MemoryMappedFiles;
using System.Net;

namespace Final
{
    public class Output
    {
        public static void Main()
        {
            var timer1 = new FormWithTimer();
            var timer2 = new FormWithTimer2();

            timer1.NewStringAvailable += new EventHandler<BaseClassThatCanRaiseEvent.StringEventArgs>(timer1_NewStringAvailable);

            timer2.NewStringAvailable += new EventHandler<BaseClassThatCanRaiseEvent.StringEventArgs>(timer2_NewStringAvailable);
        }

        static void timer1_NewStringAvailable(object sender, BaseClassThatCanRaiseEvent.StringEventArgs e)
        {
            var theString = e.Value;

            //To something with 'theString' that came from timer 1
            Console.WriteLine("Just got: " + theString);
        }

        static void timer2_NewStringAvailable(object sender, BaseClassThatCanRaiseEvent.StringEventArgs e)
        {
            var theString2 = e.Value;

            //To something with 'theString2' that came from timer 2
            Console.WriteLine("Just got: " + theString2);
        }
    }

    public abstract class BaseClassThatCanRaiseEvent
    {
        /// <summary>
        /// This is a custom EventArgs class that exposes a string value
        /// </summary>
        public class StringEventArgs : EventArgs
        {
            public StringEventArgs(string value)
            {
                Value = value;
            }

            public string Value { get; private set; }
        }

        //The event itself that people can subscribe to
        public event EventHandler<StringEventArgs> NewStringAvailable;

        /// <summary>
        /// Helper method that raises the event with the given string
        /// </summary>
        protected void RaiseEvent(string value)
        {
            var e = NewStringAvailable;
            if (e != null)
                e(this, new StringEventArgs(value));
        }
    }

    public partial class FormWithTimer : BaseClassThatCanRaiseEvent
    {
        Timer timer = new Timer();

        public FormWithTimer()
        {
            timer = new System.Timers.Timer(200000);

            timer.Elapsed += new ElapsedEventHandler(timer_Tick); // Everytime timer ticks, timer_Tick will be called
            timer.Interval = (200000);             // Timer will tick evert 10 seconds
            timer.Enabled = true;                       // Enable the timer
            timer.Start();                              // Start the timer
        }

        void timer_Tick(object sender, EventArgs e)
        {
            var url = @"https://gmail.google.com/gmail/feed/atom";
            var USER = "usr";
            var PASS = "pass";

            var encoded = TextToBase64(USER + ":" + PASS);

            var myWebRequest = HttpWebRequest.Create(url);
            myWebRequest.Method = "POST";
            myWebRequest.ContentLength = 0;
            myWebRequest.Headers.Add("Authorization", "Basic " + encoded);

            var response = myWebRequest.GetResponse();
            var stream = response.GetResponseStream();

            XmlReader reader = XmlReader.Create(stream);
            System.Text.StringBuilder gml = new System.Text.StringBuilder();
            while (reader.Read())
                if (reader.NodeType == XmlNodeType.Element)
                    if (reader.Name == "fullcount")
                    {
                        gml.Append(reader.ReadElementContentAsString()).Append(",");
                    }
            RaiseEvent(gml.ToString());
            // Console.WriteLine(gml.ToString());

        }

        public static string TextToBase64(string sAscii)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            byte[] bytes = encoding.GetBytes(sAscii);
            return System.Convert.ToBase64String(bytes, 0, bytes.Length);
        }
    }


    public partial class FormWithTimer2 : BaseClassThatCanRaiseEvent
    {
        Timer timer = new Timer();

        public FormWithTimer2()
        {
            timer = new System.Timers.Timer(1000);

            timer.Elapsed += new ElapsedEventHandler(timer_Tick2); // Everytime timer ticks, timer_Tick will be called
            timer.Interval = (1000);             // Timer will tick evert 10 seconds
            timer.Enabled = true;                       // Enable the timer
            timer.Start();                              // Start the timer
        }

        void timer_Tick2(object sender, EventArgs e)
        {
            using (var file = MemoryMappedFile.OpenExisting("AIDA64_SensorValues"))
            {
                using (var readerz = file.CreateViewAccessor(0, 0))
                {
                    var bytes = new byte[194];
                    var encoding = Encoding.ASCII;
                    readerz.ReadArray<byte>(0, bytes, 0, bytes.Length);

                    //File.WriteAllText("C:\\myFile.txt", encoding.GetString(bytes));

                    StringReader stringz = new StringReader(encoding.GetString(bytes));

                    var readerSettings = new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Fragment };
                    using (var reader = XmlReader.Create(stringz, readerSettings))
                    {
                        System.Text.StringBuilder aida = new System.Text.StringBuilder();
                        while (reader.Read())
                        {
                            using (var fragmentReader = reader.ReadSubtree())
                            {
                                if (fragmentReader.Read())
                                {
                                    reader.ReadToFollowing("value");
                                    //Console.WriteLine(reader.ReadElementContentAsString() + ",");
                                    aida.Append(reader.ReadElementContentAsString()).Append(",");
                                }
                            }
                        }
                        RaiseEvent(aida.ToString());
                        //Console.WriteLine(aida.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-25T14:15:09+00:00Added an answer on May 25, 2026 at 2:15 pm

    You are exiting your Main method (which will stop your application) without waiting for your results. Just add a Console.ReadLine() for it to wait:

    public static void Main()
    {
        var timer1 = new FormWithTimer();
        var timer2 = new FormWithTimer2();
    
        timer1.NewStringAvailable += new EventHandler<BaseClassThatCanRaiseEvent.StringEventArgs>(timer1_NewStringAvailable);
        timer2.NewStringAvailable += new EventHandler<BaseClassThatCanRaiseEvent.StringEventArgs>(timer2_NewStringAvailable);
        Console.ReadLine();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ive been working on a program. i has 3 classes. 2 of the classes
I've been working on a weather forecaster for a program that I use, and
I've been working with a program someone else has made and I wanted to
I've been writing a Java program that aides in cutting and working with sprites,
I have a Java application that I've been working on and I just realized
So I have a library I'm working on that has, or will have, optimised
I've been working on a project of porting an old solaris CL program to
Ive been working with the twitter oauth and api and im having a weird
ive been working on c++ on linux for the past 2 years,and switched to
I've been working on a project that accesses the WMI to get information about

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.