C# code snippet need help converting to VB
-
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!
-
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!
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 SubAnd 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... -
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 SubAnd 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...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!
-
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!
Private Sub test()
Dim start As ThreadStart = Function() AnonymousMethod1()
HelpClass.Form.BeginInvoke(start)
End SubPrivate 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 FunctionDavid Anton Convert between VB, C#, C++, & Java (http://www.tangiblesoftwaresolutions.com)
-
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!
Look at this site ,please convet csharp-to-vb :omg: :omg: