Converting a WCF project from C# to VB
-
I am having trouble converting this section of code from c# to vb also not all that versed in threading. This code came from an example I found on Code project http://www.codeproject.com/KB/webservices/wcftransfer.aspx?msg=3269789 Any help would be appreciated thanks in advance
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);
Worked on my Machine!
-
I am having trouble converting this section of code from c# to vb also not all that versed in threading. This code came from an example I found on Code project http://www.codeproject.com/KB/webservices/wcftransfer.aspx?msg=3269789 Any help would be appreciated thanks in advance
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);
Worked on my Machine!
Converting from C# to VB? Why would you want to ruin perfectly good code? ;P
I know the language. I've read a book. - _Madmatt
-
Converting from C# to VB? Why would you want to ruin perfectly good code? ;P
I know the language. I've read a book. - _Madmatt
-
Not looking for a my language is better than your language debate, just a little help that's all :cool:
Worked on my Machine!
Lighten up, no debate was called for, notice the joke icon. However, you seem very defensive in your choice. Guilty feelings, or feelings of inadequency perhaps? ;P
I know the language. I've read a book. - _Madmatt
-
Lighten up, no debate was called for, notice the joke icon. However, you seem very defensive in your choice. Guilty feelings, or feelings of inadequency perhaps? ;P
I know the language. I've read a book. - _Madmatt
-
I am having trouble converting this section of code from c# to vb also not all that versed in threading. This code came from an example I found on Code project http://www.codeproject.com/KB/webservices/wcftransfer.aspx?msg=3269789 Any help would be appreciated thanks in advance
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);
Worked on my Machine!
I'll try to be a little bit more specific This is the block of code I am trying to translate
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 what I've got so far, my problem is on the first line AddressOf
'Dim start As New ThreadStart(AddressOf) <-- Not sure what this is a delegate of a function, form, ect... 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
Worked on my Machine!
-
Lighten up, no debate was called for, notice the joke icon. However, you seem very defensive in your choice. Guilty feelings, or feelings of inadequency perhaps? ;P
I know the language. I've read a book. - _Madmatt
One would think someone who wants to use VB would have a better sense of humor! :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
One would think someone who wants to use VB would have a better sense of humor! :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
He's just feeling frustrated with all the # edges taken off his language ;P
I know the language. I've read a book. - _Madmatt
-
I'll try to be a little bit more specific This is the block of code I am trying to translate
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 what I've got so far, my problem is on the first line AddressOf
'Dim start As New ThreadStart(AddressOf) <-- Not sure what this is a delegate of a function, form, ect... 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
Worked on my Machine!
That looks like Forms, not WCF. In the docs there's sample code for invoking a delegate asynchronously: Control.BeginInvoke Method (Delegate)[^]
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
He's just feeling frustrated with all the # edges taken off his language ;P
I know the language. I've read a book. - _Madmatt
-
That looks like Forms, not WCF. In the docs there's sample code for invoking a delegate asynchronously: Control.BeginInvoke Method (Delegate)[^]
Mark Salsbery Microsoft MVP - Visual C++ :java:
Sorry, still having trouble here is the entire proc I am trying to recreate in VB
public IEnumerable<object> SendQuery(string ip, FilesTransfer transfer, int sport) { int port = 0; switch (transfer.Action) { case Action.Invite: { port = HelpClass.GetAvailablePort(); if (MessageBox.Show(string.Format("Accept {0} files from {1}", transfer.Files.Count, transfer.Name), "Files", MessageBoxButtons.YesNo) == DialogResult.Yes) { 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); break; } else return new List<object>() { (int)InviteRusult.Cancel, 0 }; } default: { return new List<object>() { (int)InviteRusult.Busy, 0 }; } } return new List<object>() { (int)InviteRusult.Ok, port }; }
An online C# to VB converter spit this out, but the IDE doesn't like 'Dim start As ThreadStart = Function() Do
Public Function SendQuery(ByVal ip As String, ByVal transfer As FilesTransfer, ByVal sport As Integer) As System.Collections.Generic.IEnumerable(Of Object) Implements ITransfer.SendQuery Dim port As Integer = 0 Select Case transfer.Action Case Action.Invite If True Then port = HelpClass.GetAvailablePort() If MessageBox.Show(String.Format("Accept {0} files from {1}", transfer.Files.Count, transfer.Name), "Files", MessageBoxButtons.YesNo) = DialogResult.Yes Then 'Dim start As ThreadStart = Function() Do ' form = New TProgress(Nothing, port) ' form.sport = sport ' form.Show()
-
Sorry, still having trouble here is the entire proc I am trying to recreate in VB
public IEnumerable<object> SendQuery(string ip, FilesTransfer transfer, int sport) { int port = 0; switch (transfer.Action) { case Action.Invite: { port = HelpClass.GetAvailablePort(); if (MessageBox.Show(string.Format("Accept {0} files from {1}", transfer.Files.Count, transfer.Name), "Files", MessageBoxButtons.YesNo) == DialogResult.Yes) { 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); break; } else return new List<object>() { (int)InviteRusult.Cancel, 0 }; } default: { return new List<object>() { (int)InviteRusult.Busy, 0 }; } } return new List<object>() { (int)InviteRusult.Ok, port }; }
An online C# to VB converter spit this out, but the IDE doesn't like 'Dim start As ThreadStart = Function() Do
Public Function SendQuery(ByVal ip As String, ByVal transfer As FilesTransfer, ByVal sport As Integer) As System.Collections.Generic.IEnumerable(Of Object) Implements ITransfer.SendQuery Dim port As Integer = 0 Select Case transfer.Action Case Action.Invite If True Then port = HelpClass.GetAvailablePort() If MessageBox.Show(String.Format("Accept {0} files from {1}", transfer.Files.Count, transfer.Name), "Files", MessageBoxButtons.YesNo) = DialogResult.Yes Then 'Dim start As ThreadStart = Function() Do ' form = New TProgress(Nothing, port) ' form.sport = sport ' form.Show()
I don't know a lick of VB.NET, but based on the doc I linked to...
Delegate Sub InvokeDelegate()
...
HelpClass.Form.BeginInvoke(New InvokeDelegate(AddressOf start))
...
Public Sub start()
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 'InvokeMethodThis uses a named-method for the delegate. The C# version uses an anonymous method for the delegate - I have no idea how that's done in VB. The VB.NET or Windows Forms forums would be a great place to ask though :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
I don't know a lick of VB.NET, but based on the doc I linked to...
Delegate Sub InvokeDelegate()
...
HelpClass.Form.BeginInvoke(New InvokeDelegate(AddressOf start))
...
Public Sub start()
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 'InvokeMethodThis uses a named-method for the delegate. The C# version uses an anonymous method for the delegate - I have no idea how that's done in VB. The VB.NET or Windows Forms forums would be a great place to ask though :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
OK, well thanks for looking at it anyway, I appreciate it, I'll keep searching, I just started working with WCF, so I though what better way to learn than to try and convert this project thanks again...
Worked on my Machine!
bubk wrote:
I just started working with WCF
This is a VB.NET language issue unrelated to WCF :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
bubk wrote:
I just started working with WCF
This is a VB.NET language issue unrelated to WCF :)
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
yep, I totally agree and understand, the reason I posted here is I thought maybe there would be a better chance of finding someone who had WCF experience and c#/vb experience :)
Worked on my Machine!