need help convert c# to VB (passing delegate into Thread constructor)

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

    #1

    need help convert c# to VB (passing delegate into Thread constructor)

    I have the following code in C# that I have trouble converting to VB(2.0):

    private delegate void openDialog();
    private void openWindowsDial og(openDialog open)
    {
    Thread thread = new Thread(new ThreadStart(ope n));
    thread.SetApart mentState(Apart mentState.STA);
    thread.Start();
    }

    I tried the following code, but it would not compile:

    Private Delegate Sub openDialog()
    Private Sub openWindowsDial og(ByVal open As openDialog)
    Dim thread As Thread = New Thread(New ThreadStart(ope n)) ' exception
    here: Error 2 'System.Threadi ng.ThreadStart' is a delegate type and requires
    a single 'addressof' expression as the only argument to the constructor.
    thread.SetApart mentState(Apart mentState.STA)
    thread.Start()
    End Sub

    Thanks in advance for any help.


  • Steve

    #2
    Re: need help convert c# to VB (passing delegate into Thread constructor)

    Excerpt from MSDN:

    "Visual Basic users can omit the ThreadStart constructor when creating a
    thread. Use the AddressOf operator when passing your method for example
    Dim t As New Thread(AddressO f ThreadProc). Visual Basic automatically
    calls the ThreadStart constructor."



    Steve C.
    MCSD,MCAD,MCSE, MCP+I,CNE,CNA,C CNA


    Sergey Poberezovskiy wrote:
    I have the following code in C# that I have trouble converting to VB(2.0):
    >
    private delegate void openDialog();
    private void openWindowsDial og(openDialog open)
    {
    Thread thread = new Thread(new ThreadStart(ope n));
    thread.SetApart mentState(Apart mentState.STA);
    thread.Start();
    }
    >
    I tried the following code, but it would not compile:
    >
    Private Delegate Sub openDialog()
    Private Sub openWindowsDial og(ByVal open As openDialog)
    Dim thread As Thread = New Thread(New ThreadStart(ope n)) ' exception
    here: Error 2 'System.Threadi ng.ThreadStart' is a delegate type and requires
    a single 'addressof' expression as the only argument to the constructor.
    thread.SetApart mentState(Apart mentState.STA)
    thread.Start()
    End Sub
    >
    Thanks in advance for any help.
    >
    >

    Comment

    • kelphis

      #3
      Re: need help convert c# to VB (passing delegate into Thread constructor)

      On Aug 27, 12:34 pm, "Sergey Poberezovskiy" <se...@compros. com.au>
      wrote:
      I have the following code in C# that I have trouble converting to VB(2.0):
      >
      private delegate void openDialog();
      private void openWindowsDial og(openDialog open)
      {
      Thread thread = new Thread(new ThreadStart(ope n));
      thread.SetApart mentState(Apart mentState.STA);
      thread.Start();
      >
      }
      >
      I tried the following code, but it would not compile:
      >
      Private Delegate Sub openDialog()
      Private Sub openWindowsDial og(ByVal open As openDialog)
      Dim thread As Thread = New Thread(New ThreadStart(ope n)) ' exception
      here: Error 2 'System.Threadi ng.ThreadStart' is a delegate type and requires
      a single 'addressof' expression as the only argument to the constructor.
      thread.SetApart mentState(Apart mentState.STA)
      thread.Start()
      End Sub
      >
      Thanks in advance for any help.
      Private Sub openWindowsDial og()
      Dim Thread as Thread = New Thread(addressO f openDialog)
      thread.SetApart mentState(Apart mentState.STA)
      thread.Start()
      End Sub

      i didnt compile this so if it doesnt work im sorry.

      Comment

      • Sergey Poberezovskiy

        #4
        Re: need help convert c# to VB (passing delegate into Thread constructor)

        Sure it does not work - you are trying to invoke the delegate declaration -
        whereas I need to invoke the specific delegate that was passed into the
        procedure.

        Anyhow, I have worked out a solution - I needed to pass AddressOf
        open.Invoke as a parameter:
        Dim Thread as Thread = New Thread(addressO f open.Invoke)

        "kelphis" <amchater@hotma il.comwrote in message
        news:1188238283 .012563.279170@ o80g2000hse.goo glegroups.com.. .
        On Aug 27, 12:34 pm, "Sergey Poberezovskiy" <se...@compros. com.au>
        wrote:
        >I have the following code in C# that I have trouble converting to
        >VB(2.0):
        >>
        >private delegate void openDialog();
        >private void openWindowsDial og(openDialog open)
        >{
        > Thread thread = new Thread(new ThreadStart(ope n));
        > thread.SetApart mentState(Apart mentState.STA);
        > thread.Start();
        >>
        >}
        >>
        >I tried the following code, but it would not compile:
        >>
        >Private Delegate Sub openDialog()
        >Private Sub openWindowsDial og(ByVal open As openDialog)
        > Dim thread As Thread = New Thread(New ThreadStart(ope n)) '
        >exception
        >here: Error 2 'System.Threadi ng.ThreadStart' is a delegate type and
        >requires
        >a single 'addressof' expression as the only argument to the constructor.
        > thread.SetApart mentState(Apart mentState.STA)
        > thread.Start()
        >End Sub
        >>
        >Thanks in advance for any help.
        >
        Private Sub openWindowsDial og()
        Dim Thread as Thread = New Thread(addressO f openDialog)
        thread.SetApart mentState(Apart mentState.STA)
        thread.Start()
        End Sub
        >
        i didnt compile this so if it doesnt work im sorry.
        >

        Comment

        • Sergey Poberezovskiy

          #5
          Re: need help convert c# to VB (passing delegate into Thread constructor)

          Steve,

          I can read the MSDN - and NEVER ask question without checking the doco
          first. Unfortunately, the question I asked is not clearly covered in MSDN,
          and your reply is totally irrelevant to the question - try to create paste
          the code into a VB class and compile by following YOUR advice.

          "Steve" <lnuxguy_NOMAIL _PLEASE_@gmail. comwrote in message
          news:OM6D3DN6HH A.464@TK2MSFTNG P02.phx.gbl...
          Excerpt from MSDN:
          >
          "Visual Basic users can omit the ThreadStart constructor when creating a
          thread. Use the AddressOf operator when passing your method for example
          Dim t As New Thread(AddressO f ThreadProc). Visual Basic automatically
          calls the ThreadStart constructor."
          >
          >
          >
          Steve C.
          MCSD,MCAD,MCSE, MCP+I,CNE,CNA,C CNA
          >
          >
          Sergey Poberezovskiy wrote:
          >I have the following code in C# that I have trouble converting to
          >VB(2.0):
          >>
          >private delegate void openDialog();
          >private void openWindowsDial og(openDialog open)
          >{
          > Thread thread = new Thread(new ThreadStart(ope n));
          > thread.SetApart mentState(Apart mentState.STA);
          > thread.Start();
          >}
          >>
          >I tried the following code, but it would not compile:
          >>
          >Private Delegate Sub openDialog()
          >Private Sub openWindowsDial og(ByVal open As openDialog)
          > Dim thread As Thread = New Thread(New ThreadStart(ope n)) '
          >exception here: Error 2 'System.Threadi ng.ThreadStart' is a delegate type
          >and requires a single 'addressof' expression as the only argument to the
          >constructor.
          > thread.SetApart mentState(Apart mentState.STA)
          > thread.Start()
          >End Sub
          >>
          >Thanks in advance for any help.

          Comment

          • Steve

            #6
            Re: need help convert c# to VB (passing delegate into Thread constructor)

            Hmmm, strange. If you read the MSDN article I quoted, you'd see the
            sample VB code right below it showing exactly how to do what you're
            asking. I don't think it could get any clearer than that.

            Just trying to help.


            Steve C.
            MCSD,MCAD,MCSE, MCP+I,CNE,CNA,C CNA


            Sergey Poberezovskiy wrote:
            Steve,
            >
            I can read the MSDN - and NEVER ask question without checking the doco
            first. Unfortunately, the question I asked is not clearly covered in MSDN,
            and your reply is totally irrelevant to the question - try to create paste
            the code into a VB class and compile by following YOUR advice.
            >
            "Steve" <lnuxguy_NOMAIL _PLEASE_@gmail. comwrote in message
            news:OM6D3DN6HH A.464@TK2MSFTNG P02.phx.gbl...
            >Excerpt from MSDN:
            >>
            >"Visual Basic users can omit the ThreadStart constructor when creating a
            >thread. Use the AddressOf operator when passing your method for example
            >Dim t As New Thread(AddressO f ThreadProc). Visual Basic automatically
            >calls the ThreadStart constructor."
            >>
            >>
            >>
            >Steve C.
            >MCSD,MCAD,MCSE ,MCP+I,CNE,CNA, CCNA
            >>
            >>
            >Sergey Poberezovskiy wrote:
            >>I have the following code in C# that I have trouble converting to
            >>VB(2.0):
            >>>
            >>private delegate void openDialog();
            >>private void openWindowsDial og(openDialog open)
            >>{
            >> Thread thread = new Thread(new ThreadStart(ope n));
            >> thread.SetApart mentState(Apart mentState.STA);
            >> thread.Start();
            >>}
            >>>
            >>I tried the following code, but it would not compile:
            >>>
            >>Private Delegate Sub openDialog()
            >>Private Sub openWindowsDial og(ByVal open As openDialog)
            >> Dim thread As Thread = New Thread(New ThreadStart(ope n)) '
            >>exception here: Error 2 'System.Threadi ng.ThreadStart' is a delegate type
            >>and requires a single 'addressof' expression as the only argument to the
            >>constructor .
            >> thread.SetApart mentState(Apart mentState.STA)
            >> thread.Start()
            >>End Sub
            >>>
            >>Thanks in advance for any help.
            >
            >

            Comment

            • Sergey Poberezovskiy

              #7
              Re: need help convert c# to VB (passing delegate into Thread constructor)

              Steve,

              to make it clear - I needed to start a thread with a delegate passed as a
              PARAMETER into a procedure, so I could not use AddressOf the parameter and
              omitting the ThreadStart does not help in any way...

              "Steve" <lnuxguy_NOMAIL _PLEASE_@gmail. comwrote in message
              news:%23H10I3N6 HHA.5184@TK2MSF TNGP03.phx.gbl. ..
              Hmmm, strange. If you read the MSDN article I quoted, you'd see the sample
              VB code right below it showing exactly how to do what you're asking. I
              don't think it could get any clearer than that.
              >
              Just trying to help.
              >
              >
              Steve C.
              MCSD,MCAD,MCSE, MCP+I,CNE,CNA,C CNA
              >
              >
              Sergey Poberezovskiy wrote:
              >Steve,
              >>
              >I can read the MSDN - and NEVER ask question without checking the doco
              >first. Unfortunately, the question I asked is not clearly covered in
              >MSDN, and your reply is totally irrelevant to the question - try to
              >create paste the code into a VB class and compile by following YOUR
              >advice.
              >>
              >"Steve" <lnuxguy_NOMAIL _PLEASE_@gmail. comwrote in message
              >news:OM6D3DN6H HA.464@TK2MSFTN GP02.phx.gbl...
              >>Excerpt from MSDN:
              >>>
              >>"Visual Basic users can omit the ThreadStart constructor when creating a
              >>thread. Use the AddressOf operator when passing your method for example
              >>Dim t As New Thread(AddressO f ThreadProc). Visual Basic automatically
              >>calls the ThreadStart constructor."
              >>>
              >>>
              >>>
              >>Steve C.
              >>MCSD,MCAD,MCS E,MCP+I,CNE,CNA ,CCNA
              >>>
              >>>
              >>Sergey Poberezovskiy wrote:
              >>>I have the following code in C# that I have trouble converting to
              >>>VB(2.0):
              >>>>
              >>>private delegate void openDialog();
              >>>private void openWindowsDial og(openDialog open)
              >>>{
              >>> Thread thread = new Thread(new ThreadStart(ope n));
              >>> thread.SetApart mentState(Apart mentState.STA);
              >>> thread.Start();
              >>>}
              >>>>
              >>>I tried the following code, but it would not compile:
              >>>>
              >>>Private Delegate Sub openDialog()
              >>>Private Sub openWindowsDial og(ByVal open As openDialog)
              >>> Dim thread As Thread = New Thread(New ThreadStart(ope n)) '
              >>>exception here: Error 2 'System.Threadi ng.ThreadStart' is a delegate
              >>>type and requires a single 'addressof' expression as the only argument
              >>>to the constructor.
              >>> thread.SetApart mentState(Apart mentState.STA)
              >>> thread.Start()
              >>>End Sub
              >>>>
              >>>Thanks in advance for any help.
              >>

              Comment

              Working...