System.Timers.Timer not firing when event handles calls entity framework RRS feed

  • Question

  • I have a windows service written in VB.NET using System.Timers.Timer instances to perform some periodic tasks. I have just migrated from .NET to .NET 4.5, using entity framework 4.3.1. The "elapsed" event handler of a timer fires up normally, as long as it does not using entity framework. When entity framework is used, the event handler does not fire. It just, doesn't fire. No exception thrown, no event log message, nothing. This didn't happen while using the .NET 4 version. Does anybody have any suggestions about it?

    Code to reproduce the error (windows service) :

    'Begin of reference code

        Dim testTimer As New System.Timers.Timer

        Protected Overrides Sub OnStart(ByVal args() As String)
                testTimer.Interval = 2 * 1000 * 60
                AddHandler testTimer.Elapsed, New System.Timers.ElapsedEventHandler(AddressOf TestTimerMethod)
                testTimer.Enabled = True
          Catch ex As Exception
                'Log the exception
            End Try
        End Sub

        Protected Sub TestTimerMethod()
                testTimer.Enabled = False
                LogWrite("Start of method")

                'If I remove the next line, the event handler is fired as it should be...
                Dim dbContext As New DASTADbContext

                'mock some time consuming tasks
                Dim i = 0
            Catch ex As Exception
                'Log the exception
                testTimer.Enabled = True
            End Try

        End Sub
    'End of reference code

    Please, note the following :
    1. I build the whole solution in x86 mode. I don't know if this is relevant.
    2. I use VS2012 to build
    3. I confirmed the above scenario using logging messages and also by debugging the whole service attaching to the respective process
    4. I am referencing Entity Framework 4.3.1, built for runtime version .NET 4

    Thank you in advance,
    Pantelis Natsiavas

    EDIT: While this still remains an issue, I think I found who to blame. For some unexplainable reason, the Installshield Limited Edition used to create the windows service setup project, did not work as expected. When I used the primary output of windows service to create the setup project, for some unexplainable reason the Installshield LE added a reference to an older and now unused DLL which used Entity Framework 4. I suppose the bug occured because of referencing Entify Framework 4 and Entity Framework 4.3 at the same time. I have switched to VS2012, .NET 4.5 and InstallShield LE at the same time. Therefore, I mistakenly supposed that .NET 4.5 was to blame. I think that this should still be considered a bug, because I have never got an exception or something that would indicate I was doing something wrong. The timer, just did not fire the respective event handler(!).

    • Edited by p.natsiavas Tuesday, December 18, 2012 7:33 AM
    Monday, December 17, 2012 10:04 AM

All replies

  • Hi,

    After you removed the references to the old version of EF the problem went away? This could be a bug in EF, though it might be difficult to track down without a repro were you ever able to boil this down to a specific repro that you could provide?

    We are seeing a lot of great Entity Framework questions (and answers) from the community on Stack Overflow. As a result, our team is going to spend more time reading and answering questions posted on Stack Overflow. We would encourage you to post questions on Stack Overflow using the entity-framework tag. We will also continue to monitor the Entity Framework forum.

    Monday, January 14, 2013 10:55 PM