示例#1
0
        static void Main(string[] args)
        {
            // start by printing out any command line arguments if there are any
            if (args.Length > 0)
            {
                Console.WriteLine("Number of command line arguments is {0}", args.Length);
                foreach (var value in args)
                {
                    Console.WriteLine(value);
                }
            }
            else
            {
                Console.WriteLine("no command line arguments");
            }

            // output current application and user settings
            Console.WriteLine("Application setting");
            Console.WriteLine("AppSetting1 = {0}", CSharpBasics.Properties.Settings.Default.AppSetting1);
            Console.WriteLine("AppSetting2 = {0}", CSharpBasics.Properties.Settings.Default.AppSetting2);
            Console.WriteLine("AppSetting3 = {0}", CSharpBasics.Properties.Settings.Default.AppSetting3);
            Console.WriteLine("UserSetting1 = {0}", CSharpBasics.Properties.Settings.Default.UserSetting1);
            Console.WriteLine("UserSetting2 = {0}", CSharpBasics.Properties.Settings.Default.UserSetting2);
            Console.WriteLine("UserSetting3 = {0}", CSharpBasics.Properties.Settings.Default.UserSetting3);

            // increment the integer user setting each time run and save it.
            // the change should show up in the output next invocation of the program
            CSharpBasics.Properties.Settings.Default.UserSetting2++;
            Properties.Settings.Default.Save();

            // use a FileSystemWatcher object as an example of an event handler function
            using (FileSystemWatcher watcher = new FileSystemWatcher())
            {
                watcher.NotifyFilter = NotifyFilters.DirectoryName | NotifyFilters.FileName;
                // watch all files in the current directory
                watcher.Path   = Directory.GetCurrentDirectory();
                watcher.Filter = "*.*";

                // add event handlers for create and delete files
                watcher.Created += new FileSystemEventHandler(OnChanged);
                watcher.Deleted += new FileSystemEventHandler(OnChanged);

                // begin watching
                watcher.EnableRaisingEvents = true;

                // test some directory functions
                MyDirectory md = new MyDirectory();
                md.TestDirectory();

                // perform text file i/o tests
                MyTextFile mtf = new MyTextFile();
                mtf.TestTextFiles();

                // perform binary file i/o tests
                MyBinaryFile mbf = new MyBinaryFile();
                mbf.TestBinaryFiles();

                // end watching since we are done doing file I/O
                watcher.EnableRaisingEvents = false;
            }

            // perform class defintion test
            MyClassTest mct = new MyClassTest();

            mct.TestClasses();

            // perform some threading tests
            MyThreadTest mtt = new MyThreadTest();

            mtt.ThreadTest();
        }