Пример #1
0
        private static void WriteData()
        {
            FileStream   fs       = File.Open(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.None);
            StreamWriter sw       = new StreamWriter(fs, Encoding.Default);
            OSHandle     osHandle = new OSHandle(fs.Handle);

            osHandle.Dispose();
            try
            {
                sw.WriteLine(text);
                sw.Close();
                fs.Close();
                Console.WriteLine("Successful writing");
            }
            catch
            {
                Console.WriteLine("Cannot write to file");
            }
            Console.ReadKey();
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Started:");
            for (int i = 0; i < 5; i++)
            {
                new Thread(new ThreadStart(Running)).Start();
            }

            Console.ReadLine();
            OSHandle handle = new OSHandle(GetStdHandle(STD_OUTPUT_HANDLE));

            handle.Dispose();
            try
            {
                Console.WriteLine("shi");
            }
            catch (Exception ex)
            {
                //
            }
        }