Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

System.Windows.Forms.Timer Control not Firing the Tick event

Posted on 2006-11-28
1
1,101 Views
Last Modified: 2012-06-27
I have an application that I'm running two hidden forms.

One is for displaying an option list to open door controllers via IP address and the system tray icon
The other is for receiving communication from a Windows CE-based device via sockets

I have two timers on this second form (frmVisitorCalling):
tmrWaiting - the timeout if the Receptionist does not respond to the popup in time
tmrButtonEnable - the timeout if the option buttons do not enable in time due to an unknown error

I load at startup the frmSysTray and within the New sub:

    Private m_frmVisitorCalling As frmVisitorCalling

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        ' Create an instance of the "Visitor Calling" form as this will control it
        If m_frmVisitorCalling Is Nothing Then m_frmVisitorCalling = New frmVisitorCalling
        ' Load a HIDDEN instance of the "Visitor Calling" form
        If Not bINIUpdated And Not m_frmVisitorCalling Is Nothing Then Call m_frmVisitorCalling.LoadHidden(Me)

    End Sub

Within the frmVisitorCalling I have the following important functions:

    Private m_bLoadHidden As Boolean
    Private m_frmSysTray As frmSysTray

    '
    ' Load this form, and then hide automatically
    '
    Public Sub LoadHidden(Optional ByVal frmSysTray As frmSysTray = Nothing)

        If Not frmSysTray Is Nothing Then m_frmSysTray = frmSysTray
        m_bLoadHidden = True
        Call MyBase.Show()

    End Sub

    Private Sub frmVisitorCalling_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

        ' If loading the form hidden, make sure it is hidden asap
        If m_bLoadHidden Then
            m_bLoadHidden = False
            Call Me.Hide()
        End If

    End Sub

    Private Sub frmVisitorCalling_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing

        ' Delete the Image file if one exists
        If m_sImageFile <> "" Then
            picCamera.Image = Nothing
            If File.Exists(m_sImageFile) Then Call FileEx.Delete(FileEx.Extract(m_sImageFile, FileEx.g_enExtractTypes.stDirectory) & "\" & "*." & FileEx.Extract(m_sImageFile, FileEx.g_enExtractTypes.stExtension))
            lblCameraNA.Visible = True
            m_sImageFile = ""
        End If

        ' Do NOT close the form, but hide it instead
        e.Cancel = True
        Call Me.Hide()

    End Sub

My issue is that if I load the frmVisitorCalling at startup, it is triggering the Tick event as expected. However, when an event is raised to show I have a socket, it tries to disable the timers and then enable them again with a configurable Interval.

The Tick event now stops triggering...

Something that could cause this, is that the Socket event is raised using a class I create, and it uses threads to accept multiple connections with a client.

If I simply read in the Timer properties, the Tick event works fine, but the moment I change one of the properties (Enabled or Interval) it stops firing the trigger event.

Any ideas what could make the instance of frmVisitorCalling lose its connection with the instance of the Timer control just because I change a property?

Many thanks,

Phil
0
Comment
Question by:Inventris
1 Comment
 
LVL 21

Accepted Solution

by:
mastoo earned 500 total points
ID: 18033943
If you're using Sytem.Windows.Forms.Timer, it isn't thread-safe (other than static methods) and runs on the main gui thread.  Without more info about how your app is structured, I'll just suggest using one of the other timers or using Invoke on a method of the form to actually make calls on the timer.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB.Net Report Printing Issue 3 54
Write to a printer using vb.net 9 38
VB.NET 2008 Winforms Signing 13 30
VB.net SQLCommandBuilder Insert New Records From DataGridView 3 25
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

808 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question