Announcement

Collapse
No announcement yet.

Parallel.ForEach not compiling, can I get a second pair of eyes?

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Parallel.ForEach not compiling, can I get a second pair of eyes?

    I need a second set of eyes, I have a script where I am trying to use a Parallel.ForEach loop, but regardless of the syntax I can not get it to compile under Mono (haven't tried .NET). From everything I understand the library exists (is in system.threading.tasks). I am on the latest mono, but the script gives multiple errors when compiling. If I comment out the Parallel.ForEach it compiles fine...

    Line generating the error appears to be: Parallel.ForEach(Of Integer)(devices, parallelOptions, AddressOf CloseDevice)


    Imports System.Collections.Generic
    Imports System.Threading
    Imports System.Threading.Tasks

    Sub Main(ByVal tagName As String)
    ' Get variables (deviceRef, deviceValue, capiString)
    ' ##TagName_Device
    ' ##TagName_OldValue
    ' ##TagName_NewValue
    If tagName = "" Then
    Dim device as Integer = HS.GetVar("##GarageDoorBuddies_Device")
    Dim oldValue as Double = HS.GetVar("##GarageDoorBuddies_OldValue")
    Dim newValue as Double = HS.GetVar("##GarageDoorBuddies_NewValue")
    ActivateDevice(device, newValue)
    Else
    Dim devices as HashSet(Of Integer) = HS.GetVar("#" + tagName + "_Devices")
    If devices Is Nothing Then Return

    Dim parallelOptions As ParallelOptions = New ParallelOptions()
    parallelOptions.MaxDegreeOfParallelism = environment.processorcount
    Parallel.ForEach(Of Integer)(devices, parallelOptions, AddressOf CloseDevice)

    'For Each device As Integer In devices
    'ActivateDevice(device, 0)
    'Next
    End If
    End Sub

    Sub CloseDevice(ByVal device as Integer)
    ActivateDevice(device, 0)
    End Sub

    Sub ActivateDevice(device as Integer, newValue As Double)
    'hs.WriteLog("GDB", "Device=" + deviceString + " NewValue=" + newValueString)
    Dim dv as Scheduler.Classes.DeviceClass = hs.GetDeviceByRef(device)
    If Not dv.Device_Type_String(nothing) = "GDB" Then Return
    Dim ipString as string = dv.Address(nothing).Trim()
    Dim ipAddress As System.Net.IPAddress
    Dim ipValid As Boolean = System.Net.IPAddress.TryParse(ipString, ipAddress)
    If ipValid = False Then Return
    'hs.WriteLog("GDB", "IP=" + ip)

    If newValue = 0 Then
    hs.GetURL(“http://" + ipString,”/client?command=door1”,FALSE,1984)
    hs.WriteLog("GDB", "Close request sent to " + ipString)
    Else
    hs.GetURL(“http://" + ipString,”/client?command=door2”,FALSE,1984)
    hs.WriteLog("GDB", "Open request sent to " + ipString)
    End If
    End Sub



    Click image for larger version

Name:	Screen Shot 2019-01-13 at 1.23.57 PM.png
Views:	0
Size:	261.7 KB
ID:	1275751

  • #2
    It looks to compile properly in Windows, although it errors when I run it (which I was expecting as I'm not passing anything to it and don't have those variables):

    Code:
    Jan-13 2:34:54 PM         Error 1    Running script C:\Program Files (x86)\HomeSeer HS3\scripts\test2.vb :Exception has been thrown by the target of an invocation.Object reference not set to an instance of an object.
    Jan-13 2:34:54 PM         Warning    A call was made to retrieve a global variable (##GarageDoorBuddies_NewValue) but that global variable has not been defined.
    Jan-13 2:34:54 PM         Warning    A call was made to retrieve a global variable (##GarageDoorBuddies_OldValue) but that global variable has not been defined.
    Jan-13 2:34:54 PM         Warning    A call was made to retrieve a global variable (##GarageDoorBuddies_Device) but that global variable has not been defined.
    Jan-13 2:34:53 PM         Event    Running script in background: C:/Program Files (x86)/HomeSeer HS3/scripts/test2.vb
    HS 3.0.0.532: 1963 Devices 1141 Events
    Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

    Comment


    • #3
      Just noticed that a bunch of the " in your GetURLs are actually “, but that could be because you did not put code tags around your script (which would make it much easier to read )
      HS 3.0.0.532: 1963 Devices 1141 Events
      Z-Wave 3.0.1.261: 122 Nodes on one Z-Net

      Comment


      • #4
        Originally posted by sparkman View Post
        Just noticed that a bunch of the " in your GetURLs are actually “, but that could be because you did not put code tags around your script (which would make it much easier to read )
        Yea, that was just the board formatting it. So it compiles in Windows, ok so a mono issue. Odd, ok that is a huge hint thank you (and I'll figure out how to use the code tag next time!)

        Comment

        Working...
        X