1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-14 02:34:07 +02:00

Dispose screenshot windows after using them to save memory

This commit is contained in:
chylex 2017-04-02 17:22:31 +02:00
parent 7c86e4e743
commit 38466878db
2 changed files with 35 additions and 19 deletions

View File

@ -27,7 +27,7 @@ public void LoadNotificationForScreenshot(TweetNotification tweet, int width, in
SetNotificationSize(width, height);
}
public void TakeScreenshotAndHide(){
public void TakeScreenshot(){
MoveToVisibleLocation();
bool border = Program.UserConfig.ShowScreenshotBorder;
@ -47,13 +47,6 @@ public void TakeScreenshotAndHide(){
Clipboard.SetImage(bmp);
}
}
Reset();
}
public void Reset(){
Location = ControlExtensions.InvisibleLocation;
browser.LoadHtml("", "about:blank");
}
}
}

View File

@ -1,29 +1,46 @@
using System;
using System.Windows.Forms;
using TweetDck.Core.Controls;
namespace TweetDck.Core.Notification.Screenshot{
sealed class TweetScreenshotManager : IDisposable{
private readonly FormNotificationScreenshotable screenshot;
private readonly Form owner;
private readonly Timer timeout;
private readonly Timer disposer;
private FormNotificationScreenshotable screenshot;
public TweetScreenshotManager(Form owner){
this.screenshot = new FormNotificationScreenshotable(Callback, owner){
CanMoveWindow = () => false
};
this.timeout = new Timer{
Interval = 10000
};
this.owner = owner;
this.timeout = new Timer{ Interval = 5000 };
this.timeout.Tick += timeout_Tick;
this.disposer = new Timer{ Interval = 1 };
this.disposer.Tick += disposer_Tick;
}
private void timeout_Tick(object sender, EventArgs e){
timeout.Stop();
screenshot.Reset();
screenshot.Location = ControlExtensions.InvisibleLocation;
disposer.Start();
}
private void disposer_Tick(object sender, EventArgs e){
disposer.Stop();
screenshot.Dispose();
screenshot = null;
}
public void Trigger(string html, int width, int height){
if (screenshot != null){
return;
}
screenshot = new FormNotificationScreenshotable(Callback, owner){
CanMoveWindow = () => false
};
screenshot.LoadNotificationForScreenshot(new TweetNotification(html, string.Empty, 0), width, height);
screenshot.Show();
timeout.Start();
@ -35,12 +52,18 @@ private void Callback(){
}
timeout.Stop();
screenshot.TakeScreenshotAndHide();
screenshot.TakeScreenshot();
screenshot.Location = ControlExtensions.InvisibleLocation;
disposer.Start();
}
public void Dispose(){
screenshot.Dispose();
timeout.Dispose();
disposer.Dispose();
if (screenshot != null){
screenshot.Dispose();
}
}
}
}