AngelinaPerez

I am writing to kindly to ask you guys for help. I have been working with the lines of code below which merely locking up and disabling the computer:

Private Sub Alert_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Alert_btn.Click

Dim conn As New SqlClient.SqlConnection(My.Settings.CSTConnectionString)
Try
If conn.State <> ConnectionState.Open Then conn.Open()
Catch ex As SqlClient.SqlException
Debug.Assert(False, ex.ToString)
End Try

Try
Dim Command As New SqlClient.SqlCommand("SELECT * FROM dbo.CUSTOMERS", conn)
Dim dataReader As SqlClient.SqlDataReader = Command.ExecuteReader(CommandBehavior.CloseConnection)

dataReader.Read()
While dataReader.HasRows

Dim newAlert As New Alert(dataReader("COMMENTS").ToString(), DateTime.Parse(dataReader("DATE").ToString()))
Me.collectionOfAlerts.Add(newAlert)

End While
conn.Close()

Console.WriteLine(conn.State.ToString) 'Closed
Catch ex As Exception
Debug.Assert(False, ex.ToString)
End Try

End Sub
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The Class, reminder linked to the button, Alert_btn is as follows:


'Class Reminder

Public Class Reminder

Dim alertDesc As String = String.Empty
Dim alertTime As DateTime = DateTime.Now
Dim isAlertOn As Boolean = False
Dim timer As New System.Timers.Timer(1000) 'every second


Public Property AlertDescription() As String

Get

Return Me.alertDesc

End Get

Set(ByVal value As String)
Me.alertDesc = value
End Set
End Property


Public Property TimeOfAlert() As DateTime
Get
Return Me.alertTime
End Get
Set(ByVal value As DateTime)
Me.alertTime = value
End Set
End Property



Public Property IsAlertActive() As Boolean
Get
Return Me.isAlertOn
End Get
Set(ByVal value As Boolean)
Me.isAlertOn = value
End Set
End Property



Public Sub New(ByVal descOfAlert As String, ByVal timeOfAlert As DateTime)

Me.alertDesc = descOfAlert
Me.alertTime = timeOfAlert
Me.isAlertOn = True
Me.timer.AutoReset = True
Me.timer.Enabled = True

AddHandler timer.Elapsed, AddressOf timer_elapsed
Me.timer.Start()


End Sub


Private Sub timer_elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs)
If Me.isAlertOn Then

If Me.alertTime = DateTime.Now Or Me.alertTime <= DateTime.Now.AddMinutes(-2) Then

System.Windows.Forms.MessageBox.Show("alert from " & Me.AlertDescription)

Me.isAlertOn = False

End If

End If



End Sub

End Class

Please guys what can I do so that this code works properly - free up and release the memory after each alert Any input is greatly appreciated. Thanks.




Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

ReneeC

Not everyone here is a guy.






Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

Soyuz

Dear ReneeC,

I am sorry that you have been offended with the word 'guys'. Well, if you're in the West especially in the US, 'guys' is now used to refer to both girls and boys. The same way as the words 'fellows' or 'Hey, people', I thought that 'guys' might be more appropriate way to address the intelligent men and women here. Thanks for raising this point.





Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

ReneeC

Hi Soyuz,

Just because something is done, even prevalently doesn't mean it doesn't have a negative impact on people. Sexism has always been prevalent. Pornography is prevalent and that doesn't mean that women do not feel that our bodies or pieces of our bodies are up for sale or to be seen as objects to be dominated.

Thank you for your consideration.






Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

ReneeC

Have you single stepped through this with the debugger

Dim dataReader As SqlClient.SqlDataReader = Command.ExecuteReader(CommandBehavior.CloseConnection)

dataReader.Read()
While dataReader.HasRows

Dim newAlert As New Alert(dataReader("COMMENTS").ToString(), DateTime.Parse(dataReader("DATE").ToString()))
Me.collectionOfAlerts.Add(newAlert)

End While
conn.Close() <---- because of the close connection above... this is not needed. when the reader is closed

But there also needs to be a

reader.close after the end while






Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

LogLivePlinko

"Not everyone here is a guy."

Not everyone here cares what gender you are.





Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

ReneeC

That would only be the shallowest of possible interpretations of what's been said.




Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

LogLivePlinko

Absolutely. That's why it is so tragic.




Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

jgalley

If there is at least one row in returned by your reader then you have an infinite loop

Code Block

dataReader.Read()

While dataReader.HasRows

Dim newAlert As New Alert(...)
Me.collectionOfAlerts.Add(newAlert)

End While

If dataReader.HasRows is true then you loop forever.

I think you might want something more like:

Code Block

While dataReader.Read()

Dim newAlert As New Alert(...)
Me.collectionOfAlerts.Add(newAlert)

End While





Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

Soyuz

jgalley,

Thank you very, very, very much. You're the main GUY and a STAR!






Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

ReneeC

He is a guy. Not everyone here is one. You want to make women invisible here and pretend we don't exist, that's your choice, not a considerate one, but is your choice.




Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

jgalley

You're most welcome Soyuz.

---------

Many men incorrectly assume that the informal masculine can/should be applied to everyone. That is unfortunate. Soyuz¡¯ post near the top demonstrates that they are sensitive to this.

Even without looking that her post count or star rating, anyone who has been trolling these forums will know that ReneeC is a V.I.P.

If anyone deservers the title ¡°Answerer¡± it is she.

---------





Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

ReneeC

oh jeez galley,

You are way too good to be dispensing such compliments. I am humbled. I do what I can in between project moments.

Please take care and I shall enjoy your answers and your solutions.

Thank you,

Renee






Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

Soyuz

Well, well, well! What about me Why don't I get one




Re: Visual Basic Express Edition Help!!! This code is killing my Computer.

ReneeC