Multithreading causes problems.

Aug 20, 2014 at 7:48 PM
I have three functions that use the line:
  Dim allDevices As IList(Of LivePacketDevice) = LivePacketDevice.AllLocalMachine
And then they will send out different UDP or Ethernet packets. Originally I set it up so that it went one by one called each function after the next. In an effort to speed my program up, I have created multithreading Tasks to run these three functions at once.

When this line is called in a threading function, it fails. Particularly it says that either winpcap is installed or that I have no devices on my PC. When it's not multithreaded, it works perfectly fine in the exact same environment.

Is there a known issue about this, or limitation on using Tasks or Threads on this dll?
Coordinator
Aug 22, 2014 at 9:24 AM
Hi sparkysword,

I don't know of such a limitation.
Can you give a short code example that reproduces the issue you're seeing?

Boaz.
Aug 25, 2014 at 1:56 PM
Sure, not a problem.

I have one main class that I call called find devices. It's a struct of just strings and integers, but it doesn't really matter in this case
  Public Shared Function finddevices(ByRef devList As List(Of NetworkSearch.device)) 

      
        'find devices
        Dim Task1 = Task(Of List(Of NetworkSearch.device)).Factory.StartNew(Function() getdevbrand1())
        Dim Task2= Task(Of List(Of NetworkSearch.device)).Factory.StartNew(Function() getdevbrand2())

        Try
            devList.AddRange(Task1 .Result())
            devList.AddRange(Task2 .Result())
        Catch ex As Exception

        End Try

     End Function
Now in threading these guys are calling two different classes, but are incredibly similar. They both build a ethernet packet and then send it out through a pcap communicator. For example:
Public Shared Function getdevbrand1() 
        Try
            Dim cameraList As List(Of camera) = (brand1.finddevices())
            Return cameraList
        Catch ex As Exception
               End Try

        Return Nothing
    End Function
in the brand1's class I have it starting like so:
 Public Shared Function finddevices() As List(Of NetworkSearch.camera)
   
         Dim adapterAddress As String = My.Settings.NICAddress

          ' Retrieve the device list from the local machine
          Dim allDevices As IList(Of LivePacketDevice) = LivePacketDevice.AllLocalMachine  'THIS is the line it fails at


'continue other code items 

        'localIPaddress & Device
        Dim localIpAddress As String = NetworkSearch.strlocalIPAddress
        Dim selectedOutputDevice As LivePacketDevice = NetworkSearch.selectedPacketDevice


'other stuff
end function
So you get the idea. At the same time I call that line to see the adapter by both brand1 and brand2. They're a very similar setup that run at the same time in multithreading. They both have that line at the beginning.

I got around it by calling that line prior and making its results global, but I was just curious if there was a reason or possible known scenario of why it was happening.
Coordinator
Aug 30, 2014 at 9:20 AM
Thanks for providing more code.
Can you give the exact error message you get? Maybe with a full call stack?