Multiple event Args in VB 2005

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cmdolcet69

    Multiple event Args in VB 2005

    Can anyone tell me if its possible to do multiple event args in vb.net?
  • Michel Posseth

    #2
    Re: Multiple event Args in VB 2005

    Yes you can

    if you mean with that a event with a argument signature of (n) elements

    like this for instance

    Public Event eHelloWorld(ByV al a As Date, ByVal b As String, ByVal c As
    Integer, ByVal d As Object, ByVal e As System.EventArg s)


    just declare it with the wanted arguments this can be value types or
    reference types


    hth

    Michel Posseth [MCP]



    "cmdolcet69 " <colin_dolcetti @hotmail.comsch reef in bericht
    news:85f63e34-a0f1-4d51-bde5-f527a47a0d36@d4 5g2000hsc.googl egroups.com...
    Can anyone tell me if its possible to do multiple event args in vb.net?

    Comment

    • Patrice

      #3
      Re: Multiple event Args in VB 2005

      Yes, what have you tried that doesn't work ?

      That said, usually the signature is always the sender and another argument
      using a class type that allows to expose whatever members are needed so my
      personal preference would be likely to stick to this convention for
      consistency unless I find some strong reason to do otherwise.

      IMO there is more behind your question. You may want to provide a bit more
      details...

      --
      Patrice

      "cmdolcet69 " <colin_dolcetti @hotmail.coma écrit dans le message de groupe
      de discussion :
      85f63e34-a0f1-4d51-bde5-f527a47a0d36...l egroups.com...
      Can anyone tell me if its possible to do multiple event args in vb.net?

      Comment

      • Armin Zingler

        #4
        Re: Multiple event Args in VB 2005

        "cmdolcet69 " <colin_dolcetti @hotmail.comsch rieb
        Can anyone tell me if its possible to do multiple event args in
        vb.net?
        Is "multiple event args" a term I should know? If not, what's it's meaning?


        Armin

        Comment

        • cmdolcet69

          #5
          Re: Multiple event Args in VB 2005

          On Oct 30, 8:03 am, "Michel Posseth" <m...@posseth.c omwrote:
          Yes you can
          >
          if you mean with that a event with a argument signature of (n) elements
          >
          like this for instance
          >
          Public Event eHelloWorld(ByV al a As Date, ByVal b As String, ByVal c As
          Integer, ByVal d As Object, ByVal e As System.EventArg s)
          >
          just declare it with the wanted arguments this can be value types or
          reference types
          >
          hth
          >
          Michel Posseth [MCP]
          >
          "cmdolcet69 " <colin_dolce... @hotmail.comsch reef in berichtnews:85f 63e34-a0f1-4d51-bde5-f527a47a0d36@d4 5g2000hsc.googl egroups.com...
          >
          Can anyone tell me if its possible to do multiple event args in vb.net?
          Ok so the sub StartWorkerThre adDualDSI1 is suppose to create (2) com
          ports so that I can read reading from (2) sources at the same
          time….currently this only reads one source at a time…. On the bottom
          of the sub I create the two COM Ports currentserial and currentserial2
          then it goes into the DoDualDSIWorkCO M! Sub and passing in only the e
          argument for the first COM port my question is how can I pass a second
          e argument into the DoDualDSIWorkCO M1? Also while in that sub it
          calls the sub GetDSIInputCOM1 the serialport is only being passed COM1
          and never COM 2 how can I get both COM’s to be passed in?????


          Public Sub StartWorkerThre adDualDSI1(ByVa l gageType As String)
          Dim expectedBaudRat e As String = "57600"
          Select Case gageType
          Case "DSI"
          AddHandler dataBackgroundW orker.DoWork, AddressOf
          DoDualDSIWorkCO M1
          AddHandler dataBackgroundW orker.RunWorker Completed,
          AddressOf DualDSIWorkComp lete
          expectedBaudRat e = "9600"

          End Select
          currentSerial = GetSerialPortUs ed(1)
          currentSerial2 = GetSerialPortUs edCOM2(2)
          ChangeCOMBaudRa teIfNecessary(e xpectedBaudRate )
          dataBackgroundW orker.RunWorker Async(New Object()
          (currentSerial} )
          dataBackgroundW orker2.RunWorke rAsync(New Object()
          {currentSerial2 })
          Me.tmrBackgroun dWorker.Enabled = True
          Me.tmrBackgroun dWorker2.Enable d = True




          Private Sub DoDualDSIWorkCO M1(ByVal sender As Object, ByVal e As
          DoWorkEventArgs )
          Try
          Dim args() As Object = e.Argument
          Dim intloop As Integer
          CType(args(0), IO.Ports.Serial Port).DiscardIn Buffer()
          muxClass.GetDua lDSIInputCOM1(C Type(args(0),
          IO.Ports.Serial Port))
          Catch ex As Exception
          tListener.AddMe thodError(ex)
          End Try
          End Sub



          Public Sub GetDualDSIInput COM1(ByVal serialPort As
          IO.Ports.Serial Port)
          Dim intloop As Integer
          Try
          serialPort.Read Timeout = 500
          serialPort.Disc ardInBuffer()

          Dim strDataCOM1 As String = String.Empty
          If Not serialPort.IsOp en Then
          strDataCOM1 = String.Empty
          Else
          strDataCOM1 = serialPort.Read Line
          End If
          If strDataCOM1.Len gth 0 Then
          COM1Active = 1
          Dim tempArray() As String
          strDataCOM1 = strDataCOM1.Rep lace(vbCrLf,
          vbTab).Replace( Chr(26), "").Replace(Chr (12), "").Replace(Chr (13), "")
          'parses out the information gathered from the COM port
          to a temp location
          tempArray = Split(strDataCO M1, vbTab)

          If serialPort.Baud Rate = 9600 Then
          DSICollector = "585 Plus"
          Get585PlusData( tempArray)
          Else
          DSICollector = "501/440"
          Get501Data(temp Array)
          End If
          End If

          Catch tex As TimeoutExceptio n
          'do nothing as this will happen while waiting
          Catch ioError As System.IO.IOExc eption
          'do nothing as this will occur sometimes when closing the
          thread
          Catch ex As Exception
          tListener.AddMe thodError(ex)
          End Try
          End Sub

          Comment

          • Armin Zingler

            #6
            Re: Multiple event Args in VB 2005

            "cmdolcet69 " <colin_dolcetti @hotmail.comsch rieb
            AddHandler dataBackgroundW orker.DoWork, AddressOf
            DoDualDSIWorkCO M1
            In the code you posted, I don't see where you add the handler to
            dataBackgroundW orker2.DoWork:

            AddHandler dataBackgroundW orker2.DoWork, AddressOf DoDualDSIWorkCO M1

            Can this be the actual problem? A general answer to your question: If the
            event is defined not by yourself, you can not change the number of
            arguments. The event handler must have the same number of arguments.



            Armin

            Comment

            • cmdolcet69

              #7
              Re: Multiple event Args in VB 2005

              On Oct 30, 8:55 am, "Armin Zingler" <az.nos...@free net.dewrote:
              "cmdolcet69 " <colin_dolce... @hotmail.comsch rieb
              >
                             AddHandler dataBackgroundW orker.DoWork, AddressOf
              DoDualDSIWorkCO M1
              >
              In the code you posted, I don't see where you add the handler to
              dataBackgroundW orker2.DoWork:
              >
              AddHandler dataBackgroundW orker2.DoWork, AddressOf DoDualDSIWorkCO M1
              >
              Can this be the actual problem? A general answer to your question: If the
              event is defined not by yourself, you can not change the number of
              arguments. The event handler must have the same number of arguments.
              >
              Armin
              Ok sorry i did make a mistake in the first sub and have now added the
              handler to dataBackgroundW orker2 however how do i add this to the
              DodualDSIWorker COM1 Sub ? how can I pass in the values of the second
              databackgroundw orker
              ?

              Comment

              • Armin Zingler

                #8
                Re: Multiple event Args in VB 2005

                "cmdolcet69 " <colin_dolcetti @hotmail.comsch rieb
                On Oct 30, 8:55 am, "Armin Zingler" <az.nos...@free net.dewrote:
                "cmdolcet69 " <colin_dolce... @hotmail.comsch rieb
                >
                AddHandler dataBackgroundW orker.DoWork, AddressOf
                DoDualDSIWorkCO M1
                >
                In the code you posted, I don't see where you add the handler to
                dataBackgroundW orker2.DoWork:
                >
                AddHandler dataBackgroundW orker2.DoWork, AddressOf DoDualDSIWorkCO M1
                >
                Can this be the actual problem? A general answer to your question: If the
                event is defined not by yourself, you can not change the number of
                arguments. The event handler must have the same number of arguments.
                >
                Armin
                Ok sorry i did make a mistake in the first sub and have now added the
                handler to dataBackgroundW orker2 however how do i add this to the
                DodualDSIWorker COM1 Sub ? how can I pass in the values of the second
                databackgroundw orker
                ?

                You wrote:

                dataBackgroundW orker.RunWorker Async(New Object() (currentSerial} )
                dataBackgroundW orker2.RunWorke rAsync(New Object() {currentSerial2 })

                You already use the first port with the first BGW and the second port with
                the second BGW. Consequently, inside DoDualDSIWorkCO M1, args(0) is the first
                or the second port. It is the first port if the method ist executed in the
                1st BGW and the 2nd port if executed in the 2nd BGW. So, I think there is no
                problem (in this part).


                Armin

                Comment

                • cmdolcet69

                  #9
                  Re: Multiple event Args in VB 2005

                  On Oct 30, 9:46 am, "Armin Zingler" <az.nos...@free net.dewrote:
                  "cmdolcet69 " <colin_dolce... @hotmail.comsch rieb
                  On Oct 30, 8:55 am, "Armin Zingler" <az.nos...@free net.dewrote:
                  >
                  >
                  >
                  "cmdolcet69 " <colin_dolce... @hotmail.comsch rieb
                  >
                  AddHandler dataBackgroundW orker.DoWork, AddressOf
                  DoDualDSIWorkCO M1
                  >
                  In the code you posted, I don't see where you add the handler to
                  dataBackgroundW orker2.DoWork:
                  >
                  AddHandler dataBackgroundW orker2.DoWork, AddressOf DoDualDSIWorkCO M1
                  >
                  Can this be the actual problem? A general answer to your question: If the
                  event is defined not by yourself, you can not change the number of
                  arguments. The event handler must have the same number of arguments.
                  >
                  Armin
                  Ok sorry i did make a mistake in the first sub and have now added the
                  handler to dataBackgroundW orker2 however how do i add this to the
                  DodualDSIWorker COM1 Sub ? how can I pass in the values of the second
                  databackgroundw orker
                  ?
                  You wrote:
                  >
                  dataBackgroundW orker.RunWorker Async(New Object() (currentSerial} )
                  dataBackgroundW orker2.RunWorke rAsync(New Object() {currentSerial2 })
                  >
                  You already use the first port with the first BGW and the second port with
                  the second BGW. Consequently, inside DoDualDSIWorkCO M1, args(0) is the first
                  or the second port. It is the first port if the method ist executed in the
                  1st BGW and the 2nd port if executed in the 2nd BGW. So, I think there isno
                  problem (in this part).
                  >
                  Armin
                  ok then how can i have them both running at the same time meaning that
                  in the sub below: my serialPort is always COM port 1 I need to ahve
                  COm 1 and COM 2 be open and reading data at the same time.... Is this
                  possible and does this make sense?

                  Public Sub GetDualDSIInput COM1(ByVal serialPort As
                  IO.Ports.Serial Port)
                  Dim intloop As Integer
                  Try
                  serialPort.Read Timeout = 500
                  serialPort.Disc ardInBuffer()

                  Dim strDataCOM1 As String = String.Empty
                  If Not serialPort.IsOp en Then
                  strDataCOM1 = String.Empty
                  Else
                  strDataCOM1 = serialPort.Read Line
                  End If
                  If strDataCOM1.Len gth 0 Then
                  COM1Active = 1
                  Dim tempArray() As String
                  strDataCOM1 = strDataCOM1.Rep lace(vbCrLf,
                  vbTab).Replace( Chr(26), "").Replace(Chr (12), "").Replace(Chr (13), "")
                  'parses out the information gathered from the COM port
                  to a temp location
                  tempArray = Split(strDataCO M1, vbTab)

                  If serialPort.Baud Rate = 9600 Then
                  DSICollector = "585 Plus"
                  Get585PlusData( tempArray)
                  Else
                  DSICollector = "501/440"
                  Get501Data(temp Array)
                  End If
                  End If

                  Catch tex As TimeoutExceptio n
                  'do nothing as this will happen while waiting
                  Catch ioError As System.IO.IOExc eption
                  'do nothing as this will occur sometimes when closing the
                  thread
                  Catch ex As Exception
                  tListener.AddMe thodError(ex)
                  End Try
                  End Sub



                  Comment

                  • Armin Zingler

                    #10
                    Re: Multiple event Args in VB 2005

                    "cmdolcet69 " <colin_dolcetti @hotmail.comsch rieb
                    You wrote:

                    dataBackgroundW orker.RunWorker Async(New Object() (currentSerial} )
                    dataBackgroundW orker2.RunWorke rAsync(New Object()
                    {currentSerial2 })

                    You already use the first port with the first BGW and the second
                    port with the second BGW. Consequently, inside DoDualDSIWorkCO M1,
                    args(0) is the first or the second port. It is the first port if
                    the method ist executed in the 1st BGW and the 2nd port if
                    executed in the 2nd BGW. So, I think there is no problem (in this
                    part).

                    Armin
                    >
                    ok then how can i have them both running at the same time meaning
                    that in the sub below: my serialPort is always COM port 1 I need to
                    ahve
                    COm 1 and COM 2 be open and reading data at the same time.... Is
                    this possible and does this make sense?
                    Yes, it makes sense. You are already creating two BGWs (background workers),
                    and you create two SerialPort objects. Each port is handled in it's own
                    thread. That's the correct approach IMO.

                    The name of the Sub is confusing because it ends with "COM1", though it
                    should handle any port. Also the names inside (strDataCOM1, COM1Active).

                    How do you see that it is always port 1? Maybe because you are watching
                    variable "COM1Active ", which is not local, anywhere else? It pretends to be
                    COM1 but it isn't always.


                    Public Sub GetDualDSIInput COM1(ByVal serialPort As
                    IO.Ports.Serial Port)
                    [...]
                    COM1Active = 1

                    Armin

                    Comment

                    • cmdolcet69

                      #11
                      Re: Multiple event Args in VB 2005

                      On Oct 30, 11:42 am, "Armin Zingler" <az.nos...@free net.dewrote:
                      "cmdolcet69 " <colin_dolce... @hotmail.comsch rieb
                      >
                      >
                      >
                      You wrote:
                      >
                      dataBackgroundW orker.RunWorker Async(New Object() (currentSerial} )
                      dataBackgroundW orker2.RunWorke rAsync(New Object()
                      {currentSerial2 })
                      >
                      You already use the first port with the first BGW and the second
                      port with the second BGW. Consequently, inside DoDualDSIWorkCO M1,
                      args(0) is the first or the second port. It is the first port if
                      the method ist executed in the 1st BGW and the 2nd port if
                      executed in the 2nd BGW. So, I think there is no problem (in this
                      part).
                      >
                      Armin
                      >
                      ok then how can i have them both running at the same time meaning
                      that in the sub below: my serialPort is always COM port 1 I need to
                      ahve
                      COm 1 and COM 2 be open and reading data at the same time.... Is
                      this possible and does this make sense?
                      >
                      Yes, it makes sense. You are already creating two BGWs (background workers),
                      and you create two SerialPort objects. Each port is handled in it's own
                      thread. That's the correct approach IMO.
                      >
                      The name of the Sub is confusing because it ends with "COM1", though it
                      should handle any port. Also the names inside (strDataCOM1, COM1Active).
                      >
                      How do you see that it is always port 1? Maybe because you are watching
                      variable "COM1Active ", which is not local, anywhere else? It pretends to be
                      COM1 but it isn't always.
                      >
                      Public Sub GetDualDSIInput COM1(ByVal serialPort As
                      IO.Ports.Serial Port)
                      [...]
                                      COM1Active = 1
                      >
                      Armin
                      I see it when i put a watch on the SerialPort variable....... .what i
                      want to do is take be able to take both serial port data at the same
                      time but when I go into the GetDualDSIInput COM1 it always seems to be
                      passing in COM1 and not COM1 and COM2 at the same time

                      Can you help very urgent!!!!

                      Comment

                      • Armin Zingler

                        #12
                        Re: Multiple event Args in VB 2005

                        "cmdolcet69 " <colin_dolcetti @hotmail.comsch rieb
                        Yes, it makes sense. You are already creating two BGWs (background
                        workers),
                        and you create two SerialPort objects. Each port is handled in it's own
                        thread. That's the correct approach IMO.

                        The name of the Sub is confusing because it ends with "COM1", though it
                        should handle any port. Also the names inside (strDataCOM1, COM1Active).

                        How do you see that it is always port 1? Maybe because you are watching
                        variable "COM1Active ", which is not local, anywhere else? It pretends to
                        be
                        COM1 but it isn't always.
                        Public Sub GetDualDSIInput COM1(ByVal serialPort As
                        IO.Ports.Serial Port)
                        [...]
                        COM1Active = 1
                        Armin
                        >
                        I see it when i put a watch on the SerialPort variable....... .
                        And then? How do you see the difference? Do they have different property
                        values that are unique to each instance?
                        what i
                        want to do is take be able to take both serial port data at the same
                        time but when I go into the GetDualDSIInput COM1 it always seems to be
                        passing in COM1 and not COM1 and COM2 at the same time
                        >
                        Can you help very urgent!!!!
                        The two threads do run at the same time. GetDualDSIInput COM1 is executed
                        twice, one time in each thread. In thread 1 it handles port 1 and in thread
                        2 it handles port 2. That's how I expect it to work. I don't see an error in
                        this regard.

                        Try this:

                        In StartWorkerThre adDualDSI1:

                        dataBackgroundW orker.RunWorker Async(New Object() {currentSerial, "port
                        1"})
                        dataBackgroundW orker2.RunWorke rAsync(New Object() {currentSerial2 ,"port
                        2"})
                        ....


                        In DoDualDSIWorkCO M1:

                        Try
                        Dim args() As Object = e.Argument
                        Debug.Print(arg s(1).ToString)
                        ...

                        Run it without interrupting or setting breakpoints. Do you only get "port 1"
                        in the debug/output window?


                        Armin

                        Comment

                        • cmdolcet69

                          #13
                          Re: Multiple event Args in VB 2005

                          On Oct 30, 12:23 pm, "Armin Zingler" <az.nos...@free net.dewrote:
                          "cmdolcet69 " <colin_dolce... @hotmail.comsch rieb
                          >
                          >
                          >
                          Yes, it makes sense. You are already creating two BGWs (background
                          workers),
                          and you create two SerialPort objects. Each port is handled in it's own
                          thread. That's the correct approach IMO.
                          >
                          The name of the Sub is confusing because it ends with "COM1", though it
                          should handle any port. Also the names inside (strDataCOM1, COM1Active).
                          >
                          How do you see that it is always port 1? Maybe because you are watching
                          variable "COM1Active ", which is not local, anywhere else? It pretendsto
                          be
                          COM1 but it isn't always.
                          >
                          Public Sub GetDualDSIInput COM1(ByVal serialPort As
                          IO.Ports.Serial Port)
                          [...]
                          COM1Active = 1
                          >
                          Armin
                          >
                          I see it when i put a watch on the SerialPort variable....... .
                          >
                          And then? How do you see the difference? Do they have different property
                          values that are unique to each instance?
                          >
                          what i
                          want to do is take be able to take both serial port data at the same
                          time but when I go into the GetDualDSIInput COM1 it always seems to be
                          passing in COM1 and not COM1 and COM2 at the same time
                          >
                          Can you help very urgent!!!!
                          >
                          The two threads do run at the same time. GetDualDSIInput COM1 is executed
                          twice, one time in each thread. In thread 1 it handles port 1 and in thread
                          2 it handles port 2. That's how I expect it to work. I don't see an errorin
                          this regard.
                          >
                          Try this:
                          >
                          In StartWorkerThre adDualDSI1:
                          >
                              dataBackgroundW orker.RunWorker Async(New Object() {currentSerial, "port
                          1"})
                              dataBackgroundW orker2.RunWorke rAsync(New Object() {currentSerial2 ,"port
                          2"})
                          ...
                          >
                          In DoDualDSIWorkCO M1:
                          >
                                  Try
                                      Dim args() As Object = e.Argument
                                      Debug.Print(arg s(1).ToString)
                                      ...
                          >
                          Run it without interrupting or setting breakpoints. Do you only get "port1"
                          in the debug/output window?
                          >
                          Armin
                          Running exactly what you say it always hits my error log and give the
                          following:

                          Error Information
                          Error Target - RunWorkerAsync
                          Error Message - This BackgroundWorke r is currently busy and cannot
                          run multiple tasks concurrently.
                          Exception Type - System.InvalidO perationExcepti on: This
                          BackgroundWorke r is currently busy and cannot run multiple tasks
                          concurrently.
                          at System.Componen tModel.Backgrou ndWorker.RunWor kerAsync(Object
                          argument)
                          at
                          LMIObjectLibrar y.NewRuntimeMet hods.StartWorke rThreadDualDSI2 (String
                          gageType) in C:\LMI\Programm ing\Software\Un iversal Gage Interface
                          \Universal Gage Interface 5.0\LMIObjectLi brary
                          \NewRuntimeMeth ods.vb:line 2395
                          at LMIObjectLibrar y.NewRuntimeMet hods.FindWhatGa gesToSelect(Gag es
                          gage) in C:\LMI\Programm ing\Software\Un iversal Gage Interface
                          \Universal Gage Interface 5.0\LMIObjectLi brary
                          \NewRuntimeMeth ods.vb:line 860
                          Stack Trace
                          at System.Componen tModel.Backgrou ndWorker.RunWor kerAsync(Object
                          argument)
                          at
                          LMIObjectLibrar y.NewRuntimeMet hods.StartWorke rThreadDualDSI2 (String
                          gageType) in C:\LMI\Programm ing\Software\Un iversal Gage Interface
                          \Universal Gage Interface 5.0\LMIObjectLi brary
                          \NewRuntimeMeth ods.vb:line 2395
                          at LMIObjectLibrar y.NewRuntimeMet hods.FindWhatGa gesToSelect(Gag es
                          gage) in C:\LMI\Programm ing\Software\Un iversal Gage Interface
                          \Universal Gage Interface 5.0\LMIObjectLi brary
                          \NewRuntimeMeth ods.vb:line 860
                          System.IO.Ports .SerialPort
                          System.IO.Ports .SerialPort
                          System.IO.Ports .SerialPort
                          System.IO.Ports .SerialPort
                          System.IO.Ports .SerialPort
                          System.IO.Ports .SerialPort
                          System.IO.Ports .SerialPort
                          System.IO.Ports .SerialPort
                          System.IO.Ports .SerialPort
                          System.IO.Ports .SerialPort

                          Comment

                          • cmdolcet69

                            #14
                            Re: Multiple event Args in VB 2005

                            On Oct 30, 12:23 pm, "Armin Zingler" <az.nos...@free net.dewrote:
                            "cmdolcet69 " <colin_dolce... @hotmail.comsch rieb
                            >
                            >
                            >
                            Yes, it makes sense. You are already creating two BGWs (background
                            workers),
                            and you create two SerialPort objects. Each port is handled in it's own
                            thread. That's the correct approach IMO.
                            >
                            The name of the Sub is confusing because it ends with "COM1", though it
                            should handle any port. Also the names inside (strDataCOM1, COM1Active).
                            >
                            How do you see that it is always port 1? Maybe because you are watching
                            variable "COM1Active ", which is not local, anywhere else? It pretendsto
                            be
                            COM1 but it isn't always.
                            >
                            Public Sub GetDualDSIInput COM1(ByVal serialPort As
                            IO.Ports.Serial Port)
                            [...]
                            COM1Active = 1
                            >
                            Armin
                            >
                            I see it when i put a watch on the SerialPort variable....... .
                            >
                            And then? How do you see the difference? Do they have different property
                            values that are unique to each instance?
                            >
                            what i
                            want to do is take be able to take both serial port data at the same
                            time but when I go into the GetDualDSIInput COM1 it always seems to be
                            passing in COM1 and not COM1 and COM2 at the same time
                            >
                            Can you help very urgent!!!!
                            >
                            The two threads do run at the same time. GetDualDSIInput COM1 is executed
                            twice, one time in each thread. In thread 1 it handles port 1 and in thread
                            2 it handles port 2. That's how I expect it to work. I don't see an errorin
                            this regard.
                            >
                            Try this:
                            >
                            In StartWorkerThre adDualDSI1:
                            >
                                dataBackgroundW orker.RunWorker Async(New Object() {currentSerial, "port
                            1"})
                                dataBackgroundW orker2.RunWorke rAsync(New Object() {currentSerial2 ,"port
                            2"})
                            ...
                            >
                            In DoDualDSIWorkCO M1:
                            >
                                    Try
                                        Dim args() As Object = e.Argument
                                        Debug.Print(arg s(1).ToString)
                                        ...
                            >
                            Run it without interrupting or setting breakpoints. Do you only get "port1"
                            in the debug/output window?
                            >
                            Armin
                            Running exactly what you say it always hits my error log and give the
                            following:

                            Error Information
                            Error Target - RunWorkerAsync
                            Error Message - This BackgroundWorke r is currently busy and cannot
                            run multiple tasks concurrently.
                            Exception Type - System.InvalidO perationExcepti on: This
                            BackgroundWorke r is currently busy and cannot run multiple tasks
                            concurrently.
                            at System.Componen tModel.Backgrou ndWorker.RunWor kerAsync(Object
                            argument)
                            at
                            LMIObjectLibrar y.NewRuntimeMet hods.StartWorke rThreadDualDSI2 (String
                            gageType) in C:\LMI\Programm ing\Software\Un iversal Gage Interface
                            \Universal Gage Interface 5.0\LMIObjectLi brary
                            \NewRuntimeMeth ods.vb:line 2395
                            at LMIObjectLibrar y.NewRuntimeMet hods.FindWhatGa gesToSelect(Gag es
                            gage) in C:\LMI\Programm ing\Software\Un iversal Gage Interface
                            \Universal Gage Interface 5.0\LMIObjectLi brary
                            \NewRuntimeMeth ods.vb:line 860
                            Stack Trace
                            at System.Componen tModel.Backgrou ndWorker.RunWor kerAsync(Object
                            argument)
                            at
                            LMIObjectLibrar y.NewRuntimeMet hods.StartWorke rThreadDualDSI2 (String
                            gageType) in C:\LMI\Programm ing\Software\Un iversal Gage Interface
                            \Universal Gage Interface 5.0\LMIObjectLi brary
                            \NewRuntimeMeth ods.vb:line 2395
                            at LMIObjectLibrar y.NewRuntimeMet hods.FindWhatGa gesToSelect(Gag es
                            gage) in C:\LMI\Programm ing\Software\Un iversal Gage Interface
                            \Universal Gage Interface 5.0\LMIObjectLi brary
                            \NewRuntimeMeth ods.vb:line 860
                            System.IO.Ports .SerialPort
                            System.IO.Ports .SerialPort
                            System.IO.Ports .SerialPort
                            System.IO.Ports .SerialPort
                            System.IO.Ports .SerialPort
                            System.IO.Ports .SerialPort
                            System.IO.Ports .SerialPort
                            System.IO.Ports .SerialPort
                            System.IO.Ports .SerialPort
                            System.IO.Ports .SerialPort

                            Comment

                            • cmdolcet69

                              #15
                              Re: Multiple event Args in VB 2005

                              On Oct 30, 12:23 pm, "Armin Zingler" <az.nos...@free net.dewrote:
                              "cmdolcet69 " <colin_dolce... @hotmail.comsch rieb
                              >
                              >
                              >
                              Yes, it makes sense. You are already creating two BGWs (background
                              workers),
                              and you create two SerialPort objects. Each port is handled in it's own
                              thread. That's the correct approach IMO.
                              >
                              The name of the Sub is confusing because it ends with "COM1", though it
                              should handle any port. Also the names inside (strDataCOM1, COM1Active).
                              >
                              How do you see that it is always port 1? Maybe because you are watching
                              variable "COM1Active ", which is not local, anywhere else? It pretendsto
                              be
                              COM1 but it isn't always.
                              >
                              Public Sub GetDualDSIInput COM1(ByVal serialPort As
                              IO.Ports.Serial Port)
                              [...]
                              COM1Active = 1
                              >
                              Armin
                              >
                              I see it when i put a watch on the SerialPort variable....... .
                              >
                              And then? How do you see the difference? Do they have different property
                              values that are unique to each instance?
                              >
                              what i
                              want to do is take be able to take both serial port data at the same
                              time but when I go into the GetDualDSIInput COM1 it always seems to be
                              passing in COM1 and not COM1 and COM2 at the same time
                              >
                              Can you help very urgent!!!!
                              >
                              The two threads do run at the same time. GetDualDSIInput COM1 is executed
                              twice, one time in each thread. In thread 1 it handles port 1 and in thread
                              2 it handles port 2. That's how I expect it to work. I don't see an errorin
                              this regard.
                              >
                              Try this:
                              >
                              In StartWorkerThre adDualDSI1:
                              >
                                  dataBackgroundW orker.RunWorker Async(New Object() {currentSerial, "port
                              1"})
                                  dataBackgroundW orker2.RunWorke rAsync(New Object() {currentSerial2 ,"port
                              2"})
                              ...
                              >
                              In DoDualDSIWorkCO M1:
                              >
                                      Try
                                          Dim args() As Object = e.Argument
                                          Debug.Print(arg s(1).ToString)
                                          ...
                              >
                              Run it without interrupting or setting breakpoints. Do you only get "port1"
                              in the debug/output window?
                              >
                              Armin
                              Running exactly what you say it always hits my error log and give the
                              following:

                              Error Information
                              Error Target - RunWorkerAsync
                              Error Message - This BackgroundWorke r is currently busy and cannot
                              run multiple tasks concurrently.
                              Exception Type - System.InvalidO perationExcepti on: This
                              BackgroundWorke r is currently busy and cannot run multiple tasks
                              concurrently.
                              at System.Componen tModel.Backgrou ndWorker.RunWor kerAsync(Object
                              argument)
                              at
                              LMIObjectLibrar y.NewRuntimeMet hods.StartWorke rThreadDualDSI2 (String
                              gageType) in C:\LMI\Programm ing\Software\Un iversal Gage Interface
                              \Universal Gage Interface 5.0\LMIObjectLi brary
                              \NewRuntimeMeth ods.vb:line 2395
                              at LMIObjectLibrar y.NewRuntimeMet hods.FindWhatGa gesToSelect(Gag es
                              gage) in C:\LMI\Programm ing\Software\Un iversal Gage Interface
                              \Universal Gage Interface 5.0\LMIObjectLi brary
                              \NewRuntimeMeth ods.vb:line 860
                              Stack Trace
                              at System.Componen tModel.Backgrou ndWorker.RunWor kerAsync(Object
                              argument)
                              at
                              LMIObjectLibrar y.NewRuntimeMet hods.StartWorke rThreadDualDSI2 (String
                              gageType) in C:\LMI\Programm ing\Software\Un iversal Gage Interface
                              \Universal Gage Interface 5.0\LMIObjectLi brary
                              \NewRuntimeMeth ods.vb:line 2395
                              at LMIObjectLibrar y.NewRuntimeMet hods.FindWhatGa gesToSelect(Gag es
                              gage) in C:\LMI\Programm ing\Software\Un iversal Gage Interface
                              \Universal Gage Interface 5.0\LMIObjectLi brary
                              \NewRuntimeMeth ods.vb:line 860
                              System.IO.Ports .SerialPort
                              System.IO.Ports .SerialPort
                              System.IO.Ports .SerialPort
                              System.IO.Ports .SerialPort
                              System.IO.Ports .SerialPort
                              System.IO.Ports .SerialPort
                              System.IO.Ports .SerialPort
                              System.IO.Ports .SerialPort
                              System.IO.Ports .SerialPort
                              System.IO.Ports .SerialPort

                              Comment

                              Working...