当前位置: 首页>>代码示例>>C#>>正文


C# SafeFileHandle.SetHandleAsInvalid方法代码示例

本文整理汇总了C#中SafeFileHandle.SetHandleAsInvalid方法的典型用法代码示例。如果您正苦于以下问题:C# SafeFileHandle.SetHandleAsInvalid方法的具体用法?C# SafeFileHandle.SetHandleAsInvalid怎么用?C# SafeFileHandle.SetHandleAsInvalid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SafeFileHandle的用法示例。


在下文中一共展示了SafeFileHandle.SetHandleAsInvalid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetStandardFile

        private static Stream GetStandardFile(int stdHandleName, FileAccess access, int bufferSize) {
            // We shouldn't close the handle for stdout, etc, or we'll break 
            // unmanaged code in the process that will print to console.
            // We should have a better way of marking this on SafeHandle.
            IntPtr handle = Win32Native.GetStdHandle(stdHandleName);
            SafeFileHandle sh = new SafeFileHandle(handle, false); 

            // If someone launches a managed process via CreateProcess, stdout 
            // stderr, & stdin could independently be set to INVALID_HANDLE_VALUE. 
            // Additionally they might use 0 as an invalid handle.
            if (sh.IsInvalid) { 
                // Minor perf optimization - get it out of the finalizer queue.
                sh.SetHandleAsInvalid();
                return Stream.Null;
            } 

            // Check whether we can read or write to this handle. 
            if (stdHandleName != Win32Native.STD_INPUT_HANDLE && !ConsoleHandleIsValid(sh)) { 
                //BCLDebug.ConsoleError("Console::ConsoleHandleIsValid for std handle "+stdHandleName+" failed, setting it to a null stream");
                return Stream.Null; 
            }

            //BCLDebug.ConsoleError("Console::GetStandardFile for std handle "+stdHandleName+" succeeded, returning handle number "+handle.ToString());
            Stream console = new __ConsoleStream(sh, access); 
            // Do not buffer console streams, or we can get into situations where
            // we end up blocking waiting for you to hit enter twice.  It was 
            // redundant. 
            return console;
        } 
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:29,代码来源:Console.cs

示例2: GetStandardFile

		private static Stream GetStandardFile(int stdHandleName, FileAccess access, int bufferSize)
		{
			IntPtr stdHandle = Win32Native.GetStdHandle(stdHandleName);
			SafeFileHandle safeFileHandle = new SafeFileHandle(stdHandle, false);
			if (safeFileHandle.IsInvalid)
			{
				safeFileHandle.SetHandleAsInvalid();
				return Stream.Null;
			}
			if (stdHandleName != -10 && !Console.ConsoleHandleIsValid(safeFileHandle))
			{
				return Stream.Null;
			}
			return new __ConsoleStream(safeFileHandle, access);
		}
开发者ID:ChristianWulf,项目名称:CSharpKDMDiscoverer,代码行数:15,代码来源:Console.cs


注:本文中的SafeFileHandle.SetHandleAsInvalid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。