gloveboxes / Windows-IoT-Core-Graphics-Library

Graphics Lib to draw, scroll & control text or symbols on multiple 8x8 LED Matrices and 7 Segment Displays (on MAX7219). Supports HT16K33 & MAX7219 LED Driver chips
24 stars 13 forks source link

Best way to clean up after? #1

Closed timothystewart6 closed 3 years ago

timothystewart6 commented 8 years ago

Hi. Thank you for this. I am curious what the best way to clean up after it executes or end the current execution?

private void ScrollText() {
    var driver = new Ht16K33();
    LED8x8Matrix matrix = new LED8x8Matrix(driver);    
            while (true) {
                matrix.ScrollStringInFromRight("Hello World 2015 ", 100);
            }
}
Exception thrown: 'System.NullReferenceException' in Glovebox.Graphics.dll

If I call this method twice, I get a null reference exception when it tries to instantiate the driver again.

gloveboxes commented 8 years ago

hey there, from memory I implemented iDisposable so try

private void ScrollText() { var driver = new Ht16K33(); using ( LED8x8Matrix matrix = new LED8x8Matrix(driver)) { while (true) { matrix.ScrollStringInFromRight("Hello World 2015 ", 100); } } }

gloveboxes commented 8 years ago

you'll be getting the null exception because trying to open the I2C bus without having previously released it..