/// <summary>
/// Invalidates <em>this</em> layer over the given Region. (In 1x1 space.)
/// </summary>
public void Invalidate(Region region)
{
if (this.Substrate != null)
{
System.Drawing.Region r = null;
try {
r = new System.Drawing.Region(region.GetRegionData());
r.Transform(InvertMatrix(this.To1x1Transform));
if (this.Substrate.InvokeRequired)
{
this.Substrate.Invoke(new SubstrateInvalidateDelegate(SubstrateInvalidate), new object[] { r });
}
else
{
this.Substrate.Invalidate(r);
}
}
catch (System.ArgumentException ex) {
// This happened once during live stream playback
// apparently inside the Invert operation above.
Debug.WriteLine(ex.ToString());
}
catch (InvalidOperationException ex) {
// This can happen due to a GDI+ threading issue when trying to clone a Transform. "Object is in use elsewhere."
Debug.WriteLine(ex.ToString());
}
finally {
if (r != null)
{
r.Dispose();
}
}
}
this.OnInvalidated(new RegionEventArgs(region));
}