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 SubCode: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




? Been staring at it for 2 hours now
.
Reply With Quote