Results 1 to 8 of 8

Thread: Calling .DLL Method from Timer_Elapsed

Threaded View

  1. #1

    Thread Starter
    Hyperactive Member gonzalioz's Avatar
    Join Date
    Sep 2009
    Location
    <body></body>
    Posts
    508

    Calling .DLL Method from Timer_Elapsed

    Hi all,

    I have a .dll file (Interop.ACTMULTILib.dll) that I use to connect to a PLC. This .dll contains a sub called ReadDeviceBlock2(byval devicename as string, byval size as integer, byref data as short).

    My console application startup thingy is a module. When I call this method in my main it works fine, if I call it from another method that was called by main it works as well.

    However, it doesn't work when I call it from my Timer_Elapsed sub? I guess this has to do something with threads but I can't figure it out.

    Any ideas ? Been staring at it for 2 hours now .


    [EDIT]
    Timer.Start is called from Main()... maybe that has something to with it?
    Code:
    Module Main
    
        Private Timer As New System.Timers.Timer
        Private PLC As New ACTMULTILib.ActEasyIF
        Private DataSet As new DataSet
    
        Private _lanes As New List(Of Lane)
    
        Public Sub Main()
    
            LoadDataSet()
            ConnectToPLC()
    
            Console.WriteLine("Press any key to continue ...")
            Console.ReadKey()
            Console.Clear()
    
            'This works:
            Dim data As Short
            PLC.ReadDeviceBlock2("D880", 1, data)
    
            AddHandler Timer.Elapsed, New Timers.ElapsedEventHandler(AddressOf Timer_Elapsed)
            Timer.Interval = 1000
            Timer.Start()
    
            Console.WriteLine("Press any key to exit ...")
            Console.ReadKey()
    
        End Sub
    Code:
        Private Sub Timer_Elapsed(ByVal sender As Object, ByVal e As Timers.ElapsedEventArgs)
    
            'This doesn't work, it will hang here forever without throwing a error:
            Dim data As Short
            PLC.ReadDeviceBlock2("D880", 1, data)
    
        End Sub
    Last edited by gonzalioz; Nov 25th, 2009 at 07:43 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width