Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. C# code snippet need help converting to VB

C# code snippet need help converting to VB

Scheduled Pinned Locked Moved Visual Basic
csharpvisual-studiowcfcomhelp
5 Posts 4 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bubk
    wrote on last edited by
    #1

    I am trying to convert this C# code to vb and am having some trouble, it is from a WCF project located here http://www.codeproject.com/KB/webservices/wcftransfer.aspx?msg=3269789 I did try a online C# to VB translator but what it spit out as code the VS IDE didn't like Here is the piece of code:

                            ThreadStart start = delegate
                            {
                                form = new TProgress(null, port);
                                form.sport = sport;
                                form.Show();
                                form.GetThread = new Thread(new ParameterizedThreadStart(form.GetInvoke));
                                form.GetThread.Start(transfer);
                            };
                            HelpClass.Form.BeginInvoke(start);
    

    this is as far as I have gotten

                        'Dim start As New ThreadStart(AddressOf ) <--Not sure what this delegate is, AddressOf "what"?
                        Dim form As New TProgress(DBNull.Value, port)
                        form.sport = sport
                        form.Show()
                        form.GetThread = New Thread(New ParameterizedThreadStart(AddressOf form.GetInvoke))
                        form.GetThread.Start(Transfer)
                        'HelpClass.Form.BeginInvoke(start)
    

    Thanks in advance...

    Worked on my Machine!

    D D M 3 Replies Last reply
    0
    • B bubk

      I am trying to convert this C# code to vb and am having some trouble, it is from a WCF project located here http://www.codeproject.com/KB/webservices/wcftransfer.aspx?msg=3269789 I did try a online C# to VB translator but what it spit out as code the VS IDE didn't like Here is the piece of code:

                              ThreadStart start = delegate
                              {
                                  form = new TProgress(null, port);
                                  form.sport = sport;
                                  form.Show();
                                  form.GetThread = new Thread(new ParameterizedThreadStart(form.GetInvoke));
                                  form.GetThread.Start(transfer);
                              };
                              HelpClass.Form.BeginInvoke(start);
      

      this is as far as I have gotten

                          'Dim start As New ThreadStart(AddressOf ) <--Not sure what this delegate is, AddressOf "what"?
                          Dim form As New TProgress(DBNull.Value, port)
                          form.sport = sport
                          form.Show()
                          form.GetThread = New Thread(New ParameterizedThreadStart(AddressOf form.GetInvoke))
                          form.GetThread.Start(Transfer)
                          'HelpClass.Form.BeginInvoke(start)
      

      Thanks in advance...

      Worked on my Machine!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Easy, put your VB code in a seperate method than create the ThreadStart using that method.

      Private Sub SomeMethodName()
      Dim form As New TProgress(DBNull.Value, port)
      form.sport = sport
      form.Show()
      form.GetThread = New Thread(New ParameterizedThreadStart(AddressOf form.GetInvoke))
      form.GetThread.Start(Transfer)
      End Sub

      And for the line you couldn't convert:

      Dim start As New ThreadStart(AddressOf SomeMethodName)
      

      Now, I'm not saying this code is going to work. Also, if this is doing what I think it's doing, it's a REALLY bad idea to create and show a form from a thread that is not the UI thread (the one your app started on).

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008
      But no longer in 2009...

      B 1 Reply Last reply
      0
      • D Dave Kreskowiak

        Easy, put your VB code in a seperate method than create the ThreadStart using that method.

        Private Sub SomeMethodName()
        Dim form As New TProgress(DBNull.Value, port)
        form.sport = sport
        form.Show()
        form.GetThread = New Thread(New ParameterizedThreadStart(AddressOf form.GetInvoke))
        form.GetThread.Start(Transfer)
        End Sub

        And for the line you couldn't convert:

        Dim start As New ThreadStart(AddressOf SomeMethodName)
        

        Now, I'm not saying this code is going to work. Also, if this is doing what I think it's doing, it's a REALLY bad idea to create and show a form from a thread that is not the UI thread (the one your app started on).

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008
        But no longer in 2009...

        B Offline
        B Offline
        bubk
        wrote on last edited by
        #3

        Thanks Dave, I believe I understand now...Right now I just want to get the project converted to VB so I can try and understand how it works in VB...yes starting another thread to create and show a form does look like a REALLY bad idea, now that you mention it. thanks again for the help

        Worked on my Machine!

        1 Reply Last reply
        0
        • B bubk

          I am trying to convert this C# code to vb and am having some trouble, it is from a WCF project located here http://www.codeproject.com/KB/webservices/wcftransfer.aspx?msg=3269789 I did try a online C# to VB translator but what it spit out as code the VS IDE didn't like Here is the piece of code:

                                  ThreadStart start = delegate
                                  {
                                      form = new TProgress(null, port);
                                      form.sport = sport;
                                      form.Show();
                                      form.GetThread = new Thread(new ParameterizedThreadStart(form.GetInvoke));
                                      form.GetThread.Start(transfer);
                                  };
                                  HelpClass.Form.BeginInvoke(start);
          

          this is as far as I have gotten

                              'Dim start As New ThreadStart(AddressOf ) <--Not sure what this delegate is, AddressOf "what"?
                              Dim form As New TProgress(DBNull.Value, port)
                              form.sport = sport
                              form.Show()
                              form.GetThread = New Thread(New ParameterizedThreadStart(AddressOf form.GetInvoke))
                              form.GetThread.Start(Transfer)
                              'HelpClass.Form.BeginInvoke(start)
          

          Thanks in advance...

          Worked on my Machine!

          D Offline
          D Offline
          Dave Doknjas
          wrote on last edited by
          #4

          Private Sub test()
          Dim start As ThreadStart = Function() AnonymousMethod1()
          HelpClass.Form.BeginInvoke(start)
          End Sub

          Private Function AnonymousMethod1() As Object
          form = New TProgress(Nothing, port)
          form.sport = sport
          form.Show()
          form.GetThread = New Thread(New ParameterizedThreadStart(AddressOf form.GetInvoke))
          form.GetThread.Start(transfer)
          Return Nothing
          End Function

          David Anton Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)

          1 Reply Last reply
          0
          • B bubk

            I am trying to convert this C# code to vb and am having some trouble, it is from a WCF project located here http://www.codeproject.com/KB/webservices/wcftransfer.aspx?msg=3269789 I did try a online C# to VB translator but what it spit out as code the VS IDE didn't like Here is the piece of code:

                                    ThreadStart start = delegate
                                    {
                                        form = new TProgress(null, port);
                                        form.sport = sport;
                                        form.Show();
                                        form.GetThread = new Thread(new ParameterizedThreadStart(form.GetInvoke));
                                        form.GetThread.Start(transfer);
                                    };
                                    HelpClass.Form.BeginInvoke(start);
            

            this is as far as I have gotten

                                'Dim start As New ThreadStart(AddressOf ) <--Not sure what this delegate is, AddressOf "what"?
                                Dim form As New TProgress(DBNull.Value, port)
                                form.sport = sport
                                form.Show()
                                form.GetThread = New Thread(New ParameterizedThreadStart(AddressOf form.GetInvoke))
                                form.GetThread.Start(Transfer)
                                'HelpClass.Form.BeginInvoke(start)
            

            Thanks in advance...

            Worked on my Machine!

            M Offline
            M Offline
            Milad Biroonvand
            wrote on last edited by
            #5

            Look at this site ,please convet csharp-to-vb :omg: :omg:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups