内存泄漏使用DispatcherTimer

时间:2013-05-13 18:40:46

标签: c# .net wpf forms timer

所以我在分析内存泄漏方面并不是最好的,但是我可以告诉我找到了一个。

我正在使用计时器来检查是否有连接,当我注释掉计时器时,我的内存泄漏就消失了。

计时器代码非常简单,如下所示:

private System.Windows.Threading.DispatcherTimer EmbdAttachTimer = new System.Windows.Threading.DispatcherTimer();
EmbdAttachTimer.Tick += new EventHandler(AttachTimer_Elapsed);
EmbdAttachTimer.Interval = new TimeSpan(0, 0, 0, 0, 500);
EmbdAttachTimer.Start();

事件处理程序的代码" AttachTimer_Elapsed"如下:

void AttachTimer_Elapsed(object sender, EventArgs e)
{
bAttached = isUnitAttached(); // simple check of USB connection
UpdateCnctStatText(); // some calls to UI elements to update them with "connected" or "not connected"
}

isUnitAttached()的代码调用库驱动函数,该函数检查usb行另一端的MSP430处理器。

bool IsUnitAttached
{ 
   bSuccess = usbI_MSP430.Connect(); 
   if (!bSuccess) 
    { 
       Console.WriteLine("Unable to connect."); 
       return false; 
    } 
    return true; 
}

相当困惑,我已经看了一遍,我以前使用委托运行UpdateCnctStatText函数,但改为DispatcherTimer希望它能解决我的问题,但没有区别。

0 个答案:

没有答案
相关问题