Tech Off Thread

7 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

Windows Forms Application (VB.Net)

Back to Forum: Tech Off
  • User profile image
    VBJB

    What would cause this and how do I fix this:

    I have a simple form that has a timer on it. It creates an instance of a class that monitors a machine we have. It checks on the machine every minute. If it finds any problems with the machine it sends an email to notify people.

    My problem is the email is not sent until I close down the form. I have a button on the form to stop the timer and disable it. I can stop the timer and the email is still not sent. However, when I close the form the email is sent. Is it something to do with threading or what?

  • User profile image
    blowdart

    VBJB wrote:

    What would cause this and how do I fix this:

    I have a simple form that has a timer on it. It creates an instance of a class that monitors a machine we have. It checks on the machine every minute. If it finds any problems with the machine it sends an email to notify people.

    My problem is the email is not sent until I close down the form. I have a button on the form to stop the timer and disable it. I can stop the timer and the email is still not sent. However, when I close the form the email is sent. Is it something to do with threading or what?



    Could we see the code behind the form?

  • User profile image
    VBJB

    Public Class Form1
       Public FMA3 As New FMA3

       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          Me.Text = "Not Monitoring"
          RefreshControls()
          Timer1.Interval = 60000
       End Sub

       Public Sub RefreshControls()
          With FMA3
             lblCurrentProgram.Text = .CurrentProgram
             lblToolNum.Text = .CurrentTool
             lblRunStat.Text = .StatusOfRun
             lblMotionStat.Text = .StatusOfMotion
             lblAlmMsg.Text = .AlarmMsg
             lblTime.Text = .TimeStamp
             If .DoNotMonitor = True Then
                Me.Text = "Not Monitoring"
             End If
          End With
       End Sub

       Private Sub cmdMonitor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdMonitor.Click
          Me.Text = "Monitoring"
          Timer1.Enabled = True
          Timer1.Start()
       End Sub

       Private Sub cmdStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStop.Click
          Me.Text = "Not Monitoring"
          Timer1.Enabled = False
          Timer1.Stop()
       End Sub

       Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
          If FMA3.DoNotMonitor = False Then
             FMA3.Refresh()
             RefreshControls()
          Else
             Timer1.Stop()
             Timer1.Enabled = False
             Me.Text = "Not Monitoring"
          End If
       End Sub
    End Class

  • User profile image
    blowdart

    heh. silly me. OK the code in the monitoring class and the bit that sends the mail?

  • User profile image
    VBJB

    Alright, I do not think it has anything to do with my code, something local. I download the send mail sample that in VB Express's help and it works the same way.

    What could it be; Norton or a setting somewhere?

  • User profile image
    VBJB

    It's Symantec doing this. If I shut the "Internet email auto protect" off the email is sent right away.

    FINALLY!

  • User profile image
    VBJB

    The class is long winded. It is just a bunch of readonly properties and two methods (one method to refresh the properties and the method below). If there is an alarm this method is run.

    Private Sub sendNotice()

       If m_NotificationSent = False Or Not SentCount > 5 Then
             Dim sb As New StringBuilder()
             sb.Append(NotificationMessage)
             Dim mailMsg As New MailMessage("<valid email address>", "<valid email address>") 
             With mailMsg
                .Subject = "Status Report"
                .Body = sb.ToString
             End With

          Try
             Dim client As New SmtpClient("<valid SMTP server>")
             client.Send(mailMsg)
             m_NotificationSent = True
             m_NotificationSentCount += 1
          Catch exp As Exception
             m_NotificationSent = False
             m_DoNotMonitor = False
          End Try
       End If
    End Sub

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.