타이머가 틱 할 때마다 응용 프로그램이 추가 메모리를 계속 사용합니다.
GetActeWindowTitle() 및 window2에 핸들을 처리하는 방법은 무엇입니까?
이 용도로 메모리 사용을 어떻게 관리해야합니까?CPU 사용량 관리
내 코드 :
public partial class Window1 : Window
{
Window2 window2 ;
System.Windows.Forms.Timer timer1;
public Window1()
{
InitializeComponent();
timer1 = new Timer();
timer1.Interval = 900000;
timer1.Tick += new EventHandler(timer1Tick);
timer1.Start();
}
private void timer1Tick(object Sender, EventArgs e)
{
window2 = new window2Window();
if (((GetActeWindowTitle().IndexOf("Outlook") != -1) ||
(GetActeWindowTitle().IndexOf("Word") != -1)))
{
window2.Close();
}
else
{
window2.Show();
window2.Topmost = true;
}
}
private string GetActeWindowTitle()
{
const int nChars = 256;
IntPtr handle = IntPtr.Zero;
StringBuilder Buff = new StringBuilder(nChars);
handle = GetForegroundWindow();
if (GetWindowText(handle, Buff, nChars) > 0)
{
return Buff.ToString();
}
return null;
}
}
CPU 사용량이나 메모리에 관한 질문입니까? 'window2Window' 란 무엇이고 IDisposable을 구현합니까? 가비지 수집 후 메모리 사용량을 어떻게 측정하고 있습니까? –
왜 windows2를 작성한 다음 닫으십니까? 왜 새로운 윈도우 2가 아닌가? – Paparazzi
제가 taskmanager를 볼 때, 메모리는 모든 타이머 틱마다 올라갑니다. –