Click here to Skip to main content
15,915,764 members
Home / Discussions / Visual Basic
   

Visual Basic

 
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 
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 
I tried your code, with some minor modifications. Instead of just have the cal. reset time, I added other levels (a warning level, and critical level) to give the user notice that calibrations are coming up. However, the form freezes once the CalMonitor thread goes to sleep. Here is my CalMonitor class:

Public Class clsCalMonitor

    Private Const WARNING_TIME As Integer = 12600       '3.5 hours
    Private Const CRITICAL_TIME As Integer = 13800      '3 hours 50 minutes
    Private Const OVER_TIME As Integer = 14400          '4 hours

    Private _lastReset As DateTime
    Private _abort As Boolean

    Public Event Cal_Warning()
    Public Event Cal_Critical()
    Public Event Cal_Over()
    Public Event Cal_ResetSuccessful()
    Public Event MonitorStopped()

    Private Sub Monitor()
        While Not _abort
            Dim timeSinceLastReset As TimeSpan = DateTime.Now.Subtract(_lastReset)

            If timeSinceLastReset.TotalSeconds >= WARNING_TIME AndAlso timeSinceLastReset.TotalSeconds < CRITICAL_TIME Then
                RaiseEvent Cal_Warning()
                Threading.Thread.Sleep(5000)
            ElseIf timeSinceLastReset.TotalSeconds >= CRITICAL_TIME AndAlso timeSinceLastReset.TotalSeconds < OVER_TIME Then
                RaiseEvent Cal_Critical()
                Threading.Thread.Sleep(5000)
            ElseIf timeSinceLastReset.TotalSeconds >= OVER_TIME Then
                RaiseEvent Cal_Over()
                Threading.Thread.Sleep(5000)
            Else
                Threading.Thread.Sleep(5000)
            End If
        End While
    End Sub

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

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

    Public Sub StopMonitor()
        _abort = True
        RaiseEvent MonitorStopped()
    End Sub


And in my main form I have:

Public Sub ReceiveFile(ByRef ReceivedFile As clsJBXFile, Optional ByVal NewJob As Boolean = True)

        StateFlag = (StateFlag Or StateType.Loading)

        CalMonitor = New clsCalMonitor
        CalMonitorThread = New Threading.Thread(AddressOf CalMonitor.StartMonitor)
        CalMonitor.StartMonitor()

        AddHandler CalMonitor.Cal_Warning, AddressOf CalMonitor_Warning
        AddHandler CalMonitor.Cal_Critical, AddressOf CalMonitor_Critical
        AddHandler CalMonitor.Cal_Over, AddressOf CalMonitor_Warning


        JBXFile = ReceivedFile

        LoadRooms()
        LoadCustoms()
        LoadSettings()

        SaveCounter = 0             'Reset Save Counter to 0
        CurrentReadingNumber = 1    'Reset CurrentReadingNumber to the first reading

        If NewJob Then
            SetForNewJob()
        Else
            SetForPreviousJob()
        End If

        StateFlag = (StateFlag And Not StateType.Loading)
        MessageFlag = MessageType.None

    End Sub



I declared the Public CalMonitor as clasCalMonitor and Public CalMonitorThread as Threading.Thread in a module. Is for some reason cause the main form to freeze when the thread in the cal. monitor thread sleeps?
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 
Questionvb.net DataView.RowFilter not working Pin
dodaddydo7-Apr-10 16:52
dodaddydo7-Apr-10 16:52 
AnswerRe: vb.net DataView.RowFilter not working Pin
Tej Aj7-Apr-10 19:45
Tej Aj7-Apr-10 19:45 

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.