Tag: handle leak

确定GDI句柄和USER对象的数量

我们为Windows窗体UI渲染引擎开发了一个小型测试套件,可以在自动运行测试用例的同时测量性能并检测内存泄漏。 现在我们也想检查手柄泄漏。 在桌面平台上,我们可以使用以下代码: [DllImport(“User32”)] private extern static int GetGuiResources(IntPtr hProcess, int uiFlags); using (var process = Process.GetCurrentProcess()) { var gdiHandles = GetGuiResources(process.Handle, 0); var userHandles = GetGuiResources(process.Handle, 1); } 此方法似乎在Windows Mobile中不可用。 是否有另一种方法可以在Windows Mobile / CE上以编程方式确定这些值?

从System.Threading.Timer在UI中调用时如何避免泄漏句柄?

看起来在System.Threading.Timer回调函数的回调中调用Winforms控件上的Invoke,直到计时器被释放。 有没有人知道如何解决这个问题? 我需要每秒轮询一次值并相应地更新UI。 我在一个测试项目中尝试过,以确保这确实是泄漏的原因,这只是以下几点: System.Threading.Timer timer; public Form1() { InitializeComponent(); timer = new System.Threading.Timer(new System.Threading.TimerCallback(DoStuff), null, 0, 500); } void DoStuff(object o) { this.Invoke(new Action(() => this.Text = “hello world”)); } 如果您在Windows任务管理器中观看,这将泄漏2个句柄/秒。