Example #1
0
        public unsafe void ReadWithOpenHandle()
        {
            using var cleaner = new TestFileCleaner();
            string cursorPath = cleaner.GetTestPath() + ".cur";

            // Create a handle with read only sharing and leave open
            using FileStream file = new FileStream(cursorPath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read);

            // Write out a valid file
            using (Stream data = TestFiles.GetTestCursor())
            {
                data.CopyTo(file);
            }
            file.Flush();

            // See that we can open a handle on it directly
            using (FileStream file2 = new FileStream(cursorPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { }

            // Try letting the OS read it in
            using (Windows.LoadCursorFromFile(cursorPath)) { };
        }