Unregister TerminalLog listeners
This commit is contained in:
parent
d0a23570bf
commit
0203290148
2 changed files with 14 additions and 3 deletions
|
|
@ -35,20 +35,23 @@ using MatterHackers.MatterControl.PrinterCommunication;
|
|||
|
||||
namespace MatterHackers.MatterControl
|
||||
{
|
||||
public class TerminalLog
|
||||
public class TerminalLog : IDisposable
|
||||
{
|
||||
private static readonly bool Is32Bit = IntPtr.Size == 4;
|
||||
|
||||
private int maxLinesToBuffer = int.MaxValue - 1;
|
||||
|
||||
private PrinterConnection printerConnection;
|
||||
|
||||
public TerminalLog(PrinterConnection printerConnection)
|
||||
{
|
||||
// Register event listeners
|
||||
printerConnection.ConnectionFailed += Instance_ConnectionFailed;
|
||||
printerConnection.Disposed += (s, e) => printerConnection.ConnectionFailed -= Instance_ConnectionFailed;
|
||||
|
||||
printerConnection.LineReceived += Printer_LineReceived;
|
||||
printerConnection.LineSent += Printer_LineSent;
|
||||
|
||||
this.printerConnection = printerConnection;
|
||||
|
||||
if (Is32Bit)
|
||||
{
|
||||
// About 10 megs worth. Average line length in gcode file is about 14 and we store strings as chars (16 bit) so 450,000 lines.
|
||||
|
|
@ -135,6 +138,13 @@ namespace MatterHackers.MatterControl
|
|||
}
|
||||
|
||||
OnHasChanged((null, true));
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
// Unregister event listeners
|
||||
printerConnection.ConnectionFailed -= Instance_ConnectionFailed;
|
||||
printerConnection.LineReceived -= Printer_LineReceived;
|
||||
printerConnection.LineSent -= Printer_LineSent;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue