none
Make AddHandler events work in Windows Service RRS feed

  • Question

  • Howdy,

    I have a Windows Service, that I'm coding with an API that has some events.
    This specific API works great in WinForms, but now under the WindowsSertice, the events just don't fire.

    A small example of my code, that it working in the winforms.

    Declaring the API: (tried with and without the "WithEvents")

    Public WithEvents ZK1 As New zkemkeeper.CZKEM

    now on the OnStart() sub, tried to register the event, as I did in the winforms:

    AddHandler ZK1.OnAttTransactionEx, AddressOf ZK1_OnAttTransactionEx

    But nothing happens.

    I saw on some forums on the web, that, for the events to work in a Windows Service, it's required some tunning, but I didn't found a code for that, or what is needed.

    How can I make the events work here?

    Thanks in advanced,
    Jorge Bastos,

    Friday, June 29, 2012 4:19 PM

Answers

  • Howdy,

    I just had a genius idea!

    Created a timmer on the service with 1 sec interval, and in the timmer event, just inserted:

     Windows.Forms.Application.DoEvents()

    And it's perfect!

    Thank you :)

    Jorge,

    • Marked as answer by jasb Monday, July 2, 2012 9:04 AM
    Monday, July 2, 2012 9:03 AM

All replies

  • This seems to be specific to the library. Try posting in http://hk.zksoftware.com:82/bbs1/viewthread.php?action=printable&tid=828

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Monday, July 2, 2012 6:57 AM
  • Howdy,

    I just had a genius idea!

    Created a timmer on the service with 1 sec interval, and in the timmer event, just inserted:

     Windows.Forms.Application.DoEvents()

    And it's perfect!

    Thank you :)

    Jorge,

    • Marked as answer by jasb Monday, July 2, 2012 9:04 AM
    Monday, July 2, 2012 9:03 AM
  • Hi Jorge,

    Welcome to the MSDN Forum.

    I have tested the timer component. It works for me.

    So I would suggest you to check whether the event is fired or not.

    Here is my test code:

        Protected Overrides Sub OnStart(ByVal args() As String)
            ' Add code here to start your service. This method should set things
            ' in motion so your service can do its work.
            'MsgBox("OnStart")
            Try
                Dim timer As New Timers.Timer
                AddHandler timer.Elapsed, AddressOf TimerTick
                timer.Interval = 1000
                timer.Start()
                EventLog1.WriteEntry("OnStart")
            Catch ex As Exception
                EventLog1.WriteEntry(ex.Message)
                Me.ExitCode = 100
                Me.Stop()
            End Try
        End Sub
    
        Private Sub TimerTick(sender As Object, e As Timers.ElapsedEventArgs)
            EventLog1.WriteEntry("TimerTick: " & e.SignalTime)
        End Sub

    And I have seen the event log in application log.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, July 2, 2012 10:00 AM
    Moderator
  • Hi Mike,

    Timer works great, I already had on in the service.
    Problem is with COM Interop, and the workarround I found was to insert the "Windows.Forms.Application.DoEvents()" in the timer event to push the COM Interop events, to make it work.

    Is there another (better/adviced) workarround for this, than what I did?

    Thanks in advanced,
    Jorge,

    Monday, July 2, 2012 3:27 PM
  • Hi Jorge,

    Actually, I didn't refresh this page before I post my reply. So I didn't see your reply. You had already done what I want to suggested.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 3, 2012 7:23 AM
    Moderator
  • Hi Mike,

    Thanks for your reply,

    I now discovered, that the same service, works fine on W7, where i'm developing, but on a Win2003 x86 doesn't, the events are not fired :(
    On a win2008 R2 works like expected.

    Any idea why the same code not working in win2003?

    Jorge,

    Tuesday, July 3, 2012 8:42 AM
  • Hi Jasb, 

    Do you check the service is start correctly?

    Do you have install the corresponding .net framework?

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 3, 2012 10:01 AM
    Moderator
  • Mike,

    Yes it started, I have that confirmation in eventlog, i even wrote an extra message in the OnStart().

    About framework yes, i'm using 2.0.

    No error thrown, but no event is fired, without code changes on W7 or R2 works.

    Ideas?

    Tuesday, July 3, 2012 10:06 AM
  • Hi Jasb,

    Please post your reproduce steps and project here: http://connect.microsoft.com/VisualStudio/ And Microsoft will check it later.

    When you finish, would you like to post the connect link here?

    Thank you very much.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, July 4, 2012 9:11 AM
    Moderator
  • Hi Mike,

    Sure, tell me before I post, should I submit it in the "Submit bug" button or other?

    Sunday, July 8, 2012 3:38 PM
  • Hi Jasb,

    Yes, you can.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, July 9, 2012 3:48 AM
    Moderator
  • Jorge,

    If you had asked your question in the proper forum for this question instead of this one about System Object then you had your answer probably quicker then in an hour.

    http://social.msdn.microsoft.com/Forums/en-US/vbgeneral


    Success
    Cor

    Monday, July 9, 2012 6:11 AM
  • Hi Mike/Cor,

    Just did, let's see the answers comming..

    Monday, July 9, 2012 8:33 AM
  • Howdy,

    No answer till now :(

    Friday, July 13, 2012 10:02 AM
  • Hi Jasb,

    I have try to involve another one into this case: http://social.msdn.microsoft.com/Forums/en-US/vbgeneral/thread/ff2d6105-37c6-47f7-b7c0-680a84f2056e 

    So please be patience. And you can follow that thread to post your ideas or concerns and so on.

    Thank you for your understanding and support.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, July 16, 2012 7:12 AM
    Moderator