Widow

Subversion Repositories:
Compare Path: Rev
With Path: Rev
?path1? @ 7  →  ?path2? @ 8
/trunk/Widow/WindowRescale.cs
@@ -1,4 +1,6 @@
using System;
using System.Threading;
using System.Threading.Tasks;
 
namespace Widow
{
@@ -8,14 +10,22 @@
 
public bool OnWindowCreate { get; set; }
 
public MainForm Form { get; set; }
public int ApplyEveryTime { get; set; }
 
public bool ApplyEveryTimeEnabled { get; set; }
 
#endregion
 
#region Private Delegates, Events, Enums, Properties, Indexers and Fields
 
private MainForm Form { get; }
 
private Windows.Windows Windows { get; }
 
private CancellationTokenSource CancellationTokenSource { get; set; }
 
private Task ApplyEveryTask { get; }
 
#endregion
 
#region Constructors, Destructors and Finalizers
@@ -22,6 +32,8 @@
 
public WindowRescale()
{
CancellationTokenSource = new CancellationTokenSource();
ApplyEveryTask = ApplyEvery(CancellationTokenSource.Token);
}
 
public WindowRescale(MainForm mainForm) : this()
@@ -39,6 +51,10 @@
public void Dispose()
{
Form.WindowCreated -= Form_WindowCreated;
CancellationTokenSource.Cancel();
ApplyEveryTask.Wait();
CancellationTokenSource.Dispose();
CancellationTokenSource = null;
}
 
#endregion
@@ -88,5 +104,25 @@
}
 
#endregion
 
#region Private Methods
 
private async Task ApplyEvery(CancellationToken cancellationToken)
{
do
{
if (!ApplyEveryTimeEnabled)
{
await Task.Delay(1000, cancellationToken);
continue;
}
 
await Task.Delay(ApplyEveryTime, cancellationToken);
 
Apply();
} while (!cancellationToken.IsCancellationRequested);
}
 
#endregion
}
}