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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:58:52+00:00 2026-05-25T06:58:52+00:00

ok so i have two programs. Code at end. one is a gmail notifier

  • 0

ok so i have two programs. Code at end.

one is a gmail notifier that outputs the number of unread mails over serial like: <02,> etc.

then i have a program that gets system(pc) temps and outputs them to serial also like: <30,42,50,> etc

they both output the same data and same format(<XX,>) at different time intervals(with different values each time). so the mail one checks every 5 minutes for mail, then outputs to serial the number of mails. but the temp program outputs the data over serial at a much fater rate at 1 sec.

ive been trying to combine the two programs into one, so that it outputs like: <02,30,42,50,> and it sends that every second so that the temps update. so the last three sets of digts change every second, but the first one wont change for every 5 minutes but 02 is still included in the output because it(the output) needs to be the same length/organization etc every time.

so what do you guys think? what is the best way to do it?

ive tried to add all the GMAIL code except static void Main (all Main does in the gmail program is call get mail and write the data to serial) to the TEMPS program, and then call the getmail Unreadz = CheckMail(); where the temps program is writing to serial(in the new combined code), but that stops the writing of data to serial so that it can check mail, which is kinda slow, so then it deosnt write the whole <02,30,42,50,> until mail is done checking. my attempt:

reader.ReadToFollowing("value");
port.Write(reader.ReadElementContentAsString() + ",");
Unreadz = CheckMail();
if (Convert.ToInt32(Unreadz) < 10) port.Write("0" + Unreadz + ",");
else port.Write("" + Unreadz + ",");

thanks.

GMAIL:

namespace GmailNotifier
{
    class Gmail
    {
        public static void Main(string[] args)
        {
            try 
            {
               SerialPort port = new SerialPort( "COM2", 9600, Parity.None, 8, StopBits.One );
               port.Open();

                string Unreadz = "0";
                while ( true )
                {
                    Unreadz = CheckMail();

                    port.Write("<");

                    Console.WriteLine("Unread Mails: " + Unreadz);
                    if (Convert.ToInt32(Unreadz) < 10) port.Write("0" + Unreadz + ",");
                    else port.Write("" + Unreadz + ",");

                    port.Write(">");

                    System.Threading.Thread.Sleep(1000);
                }
            } catch ( Exception ee ) { Console.WriteLine( ee.Message ); }

        }

        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 static string CheckMail() 
        {
            string result = "0";

            try 
            {
                var url = @"hsttps://gmail.google.com/gmail/feed/atom";
                var USER = <uname>;
                var PASS = <password>;

                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 );
                while ( reader.Read())
                    if ( reader.NodeType == XmlNodeType.Element )
                        if ( reader.Name == "fullcount" ) 
                        {
                            result = reader.ReadElementContentAsString();
                            return result;
                        }
            } catch ( Exception ee ) { Console.WriteLine( ee.Message ); }
              return result;
        }

    }
}

TEMPS:

namespace AIDA64_Reader_SerailOut
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Reading AIDA64 Shared Memory and Sending to Serial");

            try
            {
                SerialPort port = new SerialPort("COM2", 9600, Parity.None, 8, StopBits.One);
                port.Open();

                while (true)
                    using (var file = MemoryMappedFile.OpenExisting("AIDA64_SensorValues"))
                    {
                        using (var readerz = file.CreateViewAccessor(0, 0))
                        {
                            var bytes = new byte[195];
                            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));

                            port.Write("<");

                            var readerSettings = new XmlReaderSettings { ConformanceLevel = ConformanceLevel.Fragment };
                            using (var reader = XmlReader.Create(stringz, readerSettings))
                            {
                                while (reader.Read())
                                {
                                    using (var fragmentReader = reader.ReadSubtree())
                                    {
                                        if (fragmentReader.Read())
                                        {
                                            reader.ReadToFollowing("value");
                                            //port.Write("<");
                                            port.Write(reader.ReadElementContentAsString() + ",");
                                            //port.Write(">");

                                        }
                                    }
                                }
                            }
                            port.Write(">");
                        }
                        System.Threading.Thread.Sleep(1000);
                    }
            }
            catch (Exception ee) { Console.WriteLine(ee.Message); }

            Console.WriteLine("Done");
            Console.ReadLine();
        }
    }
}
  • 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-25T06:58:52+00:00Added an answer on May 25, 2026 at 6:58 am

    First of all, you need to run your mail-checker on a background thread. Try the BackgroundWorker component on for size.

    Second, use a Timer to fire off your temperature updates instead of sleeping the thread.

    To combine the two programs, I’d start by changing the existing classes to raise events when something important happens. For example, temp will raise an event every 1 second, and the event args will contain the data.

    The mail checker on the other hand, will only raise an event when it has finished checking for mail; perhaps only when the number of unread messages has changed from the last check.

    Finally, create a new class that subscribes to the events from each of the existing programs and writes to the serial port whenever an event is fired. This class can store the last reported unread message count in a private field and reuse that every time until a new event is fired to update that value.

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

Sidebar

Related Questions

I have two programs: one CLI program, and one GUI. The GUI is a
I have two (UNIX) programs A and B that read and write from stdin/stdout.
I have two begininer programs, both using the 'while' function, one works correctly, and
I need an XML-serializable dictionary. Actually, I now have two quite different programs that
I am developing two java programs that run in separate VM's that have a
I have two programs, Writer and Reader. I have a FIFO from Writer to
I have the following two programs: long startTime = System.currentTimeMillis(); for (int i =
I've got a table recording views of programs. Each program can have two different
I have recently been put in charge of debugging two different programs which will
I would like a batch file to launch two separate programs then have the

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.