Click here to Skip to main content
15,923,374 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: USB Software Pin
Dave Kreskowiak11-Apr-10 14:24
mveDave Kreskowiak11-Apr-10 14:24 
GeneralRe: USB Software Pin
FeRtoll11-Apr-10 19:21
FeRtoll11-Apr-10 19:21 
GeneralRe: USB Software Pin
Dave Kreskowiak12-Apr-10 2:15
mveDave Kreskowiak12-Apr-10 2:15 
GeneralRe: USB Software Pin
Eddy Vluggen12-Apr-10 7:41
professionalEddy Vluggen12-Apr-10 7:41 
GeneralRe: USB Software Pin
FeRtoll13-Apr-10 5:26
FeRtoll13-Apr-10 5:26 
QuestionCross-thread communication Pin
Dominick Marciano8-Apr-10 7:19
professionalDominick Marciano8-Apr-10 7:19 
AnswerRe: Cross-thread communication Pin
Luc Pattyn8-Apr-10 7:52
sitebuilderLuc Pattyn8-Apr-10 7:52 
AnswerRe: Cross-thread communication [modified] Pin
William Winner8-Apr-10 10:42
William Winner8-Apr-10 10:42 
Hopefully, you created a new class for the CalMonitor. That CalMonitor class should have a couple of things. One, an event that can fire when you want to send the re-calibrate message. The second is a variable that holds a time that it was last reset. The third is a sub that checks if it was reset recently enough, then if it wasn't, raises the event, and if it was, sleeps until the next re-calibration needs to be done.

Here's an example class that I just wrote up and tested:

VB
Public Class CalMonitor
    Private _lastReset As DateTime
    Private Const SecondsBetweenCalibrationsAllowed As Integer = 30
    Private _abort As Boolean

    Public Event TimeToCalibrate()
    Public Event ResetSuccessful()

    Public Sub New()
        _lastReset = DateTime.Now
        _abort = False
    End Sub

    'need to re-calibrate every 30 seconds
    Public Sub StartMonitor()
        While Not _abort
            Dim timeSinceLastReset As TimeSpan = DateTime.Now.Subtract(_lastReset)

            If timeSinceLastReset.TotalSeconds > SecondsBetweenCalibrationsAllowed Then
                RaiseEvent TimeToCalibrate()
                Threading.Thread.Sleep(5000)
            Else
                If ((SecondsBetweenCalibrationsAllowed - _
                    timeSinceLastReset.TotalSeconds) * 100) < 5000 Then
                    Threading.Thread.Sleep((SecondsBetweenCalibrationsAllowed - _
                                            timeSinceLastReset.TotalSeconds) * 100)
                Else
                    Threading.Thread.Sleep(5000)
                End If
            End If
        End While
    End Sub

    Public Sub CalibrationReset()
        _lastReset = DateTime.Now
        RaiseEvent ResetSuccessful()
    End Sub

    Public Sub StopMonitor()
        _abort = True
    End Sub

End Class


Then, the form looks like:
VB
Public Class Form1
    Private myCalMonitor As CalMonitor
    Private calMonitorThread As Threading.Thread

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                           Handles MyBase.Load
        myCalMonitor = New CalMonitor
        AddHandler myCalMonitor.TimeToCalibrate, AddressOf CalMonitor_TimeToReset

        calMonitorThread = New Threading.Thread(AddressOf myCalMonitor.StartMonitor)
        calMonitorThread.Start()
    End Sub

    Private Sub Form1_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        myCalMonitor.StopMonitor()
        Me.Hide()
        calMonitorThread.Join()
    End Sub

    Private Sub CalMonitor_TimeToReset()
        MessageBox.Show("Time to reset calibration")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
                              Handles Button1.Click
        myCalMonitor.CalibrationReset()
    End Sub
End Class

modified on Thursday, April 8, 2010 7:00 PM

GeneralRe: Cross-thread communication Pin
Dominick Marciano8-Apr-10 14:53
professionalDominick Marciano8-Apr-10 14:53 
GeneralRe: Cross-thread communication Pin
Dominick Marciano9-Apr-10 4:04
professionalDominick Marciano9-Apr-10 4:04 
GeneralRe: Cross-thread communication Pin
Dominick Marciano9-Apr-10 4:16
professionalDominick Marciano9-Apr-10 4:16 
GeneralRe: Cross-thread communication Pin
William Winner9-Apr-10 6:00
William Winner9-Apr-10 6:00 
QuestionSEHException in vb.net2008 [modified] Pin
FgrAlomah8-Apr-10 6:45
FgrAlomah8-Apr-10 6:45 
AnswerRe: SEHException in vb.net2008 Pin
Luc Pattyn8-Apr-10 7:08
sitebuilderLuc Pattyn8-Apr-10 7:08 
AnswerRe: SEHException in vb.net2008 Pin
FgrAlomah8-Apr-10 7:31
FgrAlomah8-Apr-10 7:31 
GeneralRe: SEHException in vb.net2008 Pin
Luc Pattyn8-Apr-10 7:54
sitebuilderLuc Pattyn8-Apr-10 7:54 
GeneralRe: SEHException in vb.net2008 Pin
FgrAlomah8-Apr-10 8:06
FgrAlomah8-Apr-10 8:06 
GeneralRe: SEHException in vb.net2008 Pin
Luc Pattyn8-Apr-10 8:10
sitebuilderLuc Pattyn8-Apr-10 8:10 
QuestionError opening serial port that work before Pin
albchinsh7-Apr-10 22:31
albchinsh7-Apr-10 22:31 
AnswerRe: Error opening serial port that work before Pin
Steven J Jowett8-Apr-10 5:23
Steven J Jowett8-Apr-10 5:23 
GeneralRe: Error opening serial port that work before Pin
albchinsh8-Apr-10 5:51
albchinsh8-Apr-10 5:51 
GeneralRe: Error opening serial port that work before Pin
DaveAuld8-Apr-10 6:25
professionalDaveAuld8-Apr-10 6:25 
GeneralRe: Error opening serial port that work before Pin
albchinsh8-Apr-10 18:29
albchinsh8-Apr-10 18:29 
AnswerRe: Error opening serial port that work before Pin
Luc Pattyn8-Apr-10 20:07
sitebuilderLuc Pattyn8-Apr-10 20:07 
GeneralRe: Error opening serial port that work before Pin
albchinsh9-Apr-10 18:13
albchinsh9-Apr-10 18:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.