Error can be raised when an EVE client is closed while the thumbnails list is being updated

This commit is contained in:
Anton Kasyanov
2018-03-28 01:44:53 +03:00
parent 6a85a9208a
commit af131cdc51
2 changed files with 16 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ namespace EveOPreview.Services.Implementation
public DwmThumbnail(IWindowManager windowManager)
{
this._windowManager = windowManager;
this._handle = IntPtr.Zero;
}
public void Register(IntPtr destination, IntPtr source)
@@ -32,12 +33,23 @@ namespace EveOPreview.Services.Implementation
return;
}
this._handle = DwmApiNativeMethods.DwmRegisterThumbnail(destination, source);
try
{
this._handle = DwmApiNativeMethods.DwmRegisterThumbnail(destination, source);
}
catch (ArgumentException)
{
// This exception is raised if the source client is already closed
// Can happen on a really slow CPU's that the window is still being
// lised in the process list yet it already cannot be used as
// a thumbnail source
this._handle = IntPtr.Zero;
}
}
public void Unregister()
{
if (!this._windowManager.IsCompositionEnabled)
if ((!this._windowManager.IsCompositionEnabled) || (this._handle == IntPtr.Zero))
{
return;
}
@@ -58,7 +70,7 @@ namespace EveOPreview.Services.Implementation
public void Update()
{
if (!this._windowManager.IsCompositionEnabled)
if ((!this._windowManager.IsCompositionEnabled) || (this._handle == IntPtr.Zero))
{
return;
}

View File

@@ -127,7 +127,7 @@ namespace EveOPreview.View
public new void Close()
{
this.IsActive = false;
this._thumbnail.Unregister();
this._thumbnail?.Unregister();
this._overlay.Close();
base.Close();
}