Call dispose at the end of the session

This commit is contained in:
Frank A. Krueger 2018-04-15 16:54:05 -07:00
parent 84912bac46
commit 57b8aa15d2
No known key found for this signature in database
GPG Key ID: 0471C67474FFE664
1 changed files with 12 additions and 0 deletions

View File

@ -23,10 +23,13 @@ namespace Ooui
DateTime lastTransmitTime = DateTime.MinValue;
readonly TimeSpan throttleInterval = TimeSpan.FromSeconds (1.0 / UI.MaxFps);
readonly bool disposeElementWhenDone;
public WebSocketSession (WebSocket webSocket, Element element, bool disposeElementWhenDone, double initialWidth, double initialHeight, CancellationToken serverToken)
: base (element, initialWidth, initialHeight)
{
this.webSocket = webSocket;
this.disposeElementWhenDone = disposeElementWhenDone;
//
// Create a new session cancellation token that will trigger
@ -112,6 +115,15 @@ namespace Ooui
}
finally {
element.MessageSent -= handleElementMessageSent;
if (disposeElementWhenDone && (element is IDisposable disposable)) {
try {
disposable.Dispose ();
}
catch (Exception ex) {
Error ("Failed to dispose of element", ex);
}
}
}
}