Каждый раз, когда отметки таймера продолжаются, приложение продолжает использовать дополнительную память.
Как настроить дескриптор в GetActeWindowTitle () и window2?
Как мне управлять использованием памяти для этого?
myКод:
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;
}
}