本文整理汇总了C#中System.Runtime.ConstrainedExecution.CriticalFinalizerObject类的典型用法代码示例。如果您正苦于以下问题:C# CriticalFinalizerObject类的具体用法?C# CriticalFinalizerObject怎么用?C# CriticalFinalizerObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CriticalFinalizerObject类属于System.Runtime.ConstrainedExecution命名空间,在下文中一共展示了CriticalFinalizerObject类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStdHandle
//引入命名空间
using System;
using System.Runtime.InteropServices;
using System.IO;
using Microsoft.Win32.SafeHandles;
namespace CriticalFinalizer
{
class Program
{
const int STD_INPUT_HANDLE = -10;
const int STD_OUTPUT_HANDLE = -11;
const int STD_ERROR_HANDLE = -12;
[DllImport("Kernel32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
public static extern IntPtr GetStdHandle(int type);
static void Main(string[] args)
{
FileStream fsIn = null;
FileStream fsOut = null;
try
{
SafeFileHandle sfhIn = new SafeFileHandle(GetStdHandle(STD_INPUT_HANDLE), false);
fsIn = new FileStream(sfhIn, FileAccess.Read);
byte[] input = new byte[] {0};
fsIn.Read(input,0,1);
SafeFileHandle sfhOut = new SafeFileHandle(GetStdHandle(STD_OUTPUT_HANDLE), false);
fsOut = new FileStream(sfhOut, FileAccess.Write);
fsOut.Write(input,0,1);
SafeFileHandle sf = fsOut.SafeFileHandle;
}
finally
{
if (fsIn != null)
{
fsIn.Close();
fsIn = null;
}
if (fsOut != null)
{
fsOut.Close();
fsOut = null;
}
}
}
}
}