if someone could direct me in the right direction because im noticing my memory goes up with time as pictures are changing.
vb.net Code:
Public Class frmSecondaryDisplay Private imageFiles() As String = Nothing ' Image index Private selected As Integer = 0 Private begin As Integer = 0 Private [end] As Integer = 0 Private Sub frmSecondaryDisplay_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Try con = New SqlConnection(cs) con.Open() cmd = New SqlCommand("SELECT RTRIM(CompanyName), RTRIM(Address),RTRIM(City),RTRIM(ContactNo),Logo from Company", con) rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection) If rdr.Read Then lblCompanyName.Text = rdr.GetValue(0).ToString() lblAddress1.Text = rdr.GetValue(1).ToString() lblAddress2.Text = rdr.GetValue(2).ToString() lblContactNo.Text = "Tel. : " & rdr.GetValue(3).ToString() Dim data As Byte() = DirectCast(rdr.GetValue(4), Byte()) Dim ms As New MemoryStream(data) If Me.PictureBox1.Image IsNot Nothing Then PictureBox1.Dispose() Me.PictureBox1.Image = Image.FromStream(ms) End If con.Close() Me.imageFiles = GetFiles(Application.StartupPath & "\Secondary Display Images", "*.jpg;*.jpeg;*.png;*.bmp;*.tif;*.tiff;*.gif") Me.selected = 0 Me.begin = 0 Me.end = imageFiles.Length ShowImage(imageFiles(selected), pbSlideShow) Catch ex As Exception MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) End Try End Sub Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Close() End Sub Public Shared Sub ShowImage(ByVal path As String, ByVal pct As PictureBox) pct.ImageLocation = path End Sub Public Shared Function GetFiles(ByVal path As String, ByVal searchPattern As String) As String() Dim patterns() As String = searchPattern.Split(";"c) Dim files As New List(Of String)() For Each filter As String In patterns ' Iterate through the directory tree and ignore the ' DirectoryNotFoundException or UnauthorizedAccessException ' exceptions. ' [url]http://msdn.microsoft.com/en-us/library/bb513869.aspx[/url] ' Data structure to hold names of subfolders to be ' examined for files. Dim dirs As New Stack(Of String)(20) If Not Directory.Exists(path) Then Throw New ArgumentException() End If dirs.Push(path) Do While dirs.Count > 0 Dim currentDir As String = dirs.Pop() Dim subDirs() As String Try subDirs = Directory.GetDirectories(currentDir) ' An UnauthorizedAccessException exception will be thrown ' if we do not have discovery permission on a folder or ' file. It may or may not be acceptable to ignore the ' exception and continue enumerating the remaining files ' and folders. It is also possible (but unlikely) that a ' DirectoryNotFound exception will be raised. This will ' happen if currentDir has been deleted by another ' application or thread after our call to Directory.Exists. ' The choice of which exceptions to catch depends entirely ' on the specific task you are intending to perform and ' also on how much you know with certainty about the ' systems on which this code will run. Catch e As UnauthorizedAccessException Continue Do Catch e As DirectoryNotFoundException Continue Do End Try Try files.AddRange(Directory.GetFiles(currentDir, filter)) Catch e As UnauthorizedAccessException Continue Do Catch e As DirectoryNotFoundException Continue Do End Try ' Push the subdirectories onto the stack for traversal. ' This could also be done before handing the files. For Each str As String In subDirs dirs.Push(str) Next str Loop Next filter Return files.ToArray() End Function Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick ShowNextImage() End Sub Private Sub ShowNextImage() Me.selected += 1 ShowImage(Me.imageFiles((Me.selected) Mod Me.imageFiles.Length), Me.pbSlideShow) End Sub End Class