help with C# and VB.NET differences ...

G

Guest

Hi,

I am trying to follow some MSDN articles on multi-threading as I need to
tryu and do it, but I am working in VB.NET and the articleas are in c#.

The articles are here: http://msdn2.microsoft.com/en-us/library/ms951089.aspx

In c# I have this code that works

delegate void ShowProgressDelegate(string pi, int totalDigits, int
digitsSoFar, out bool cancel);

void ShowProgress(string pi, int totalDigits, int digitsSoFar, out bool
cancel)
{

.....

ShowProgressDelegate showProgress = new ShowProgressDelegate(ShowProgress);
object inoutCancel = false; // Avoid boxing and losing our return value

// Show progress synchronously (so we can check for cancel)
//Invoke(showProgress, new object[] { pi, totalDigits, digitsSoFar,
inoutCancel});
cancel = (bool)inoutCancel;

// Show progress asynchronously
BeginInvoke(showProgress, new object[] { pi, totalDigits, digitsSoFar,
inoutCancel});

.....

}

how do I do that in VB.NET please?

I tried this below but it shows a compile error:
Delegate Sub ShowProgressDelegate(ByVal dblPctDone As Integer, ByVal
iMax As Integer, ByRef bCancel As Boolean)

Private Sub cmdExecute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdExecute.Click

Dim ShowProgress As New ShowProgressDelegate(AddressOf ShowProgress())

thanks for any help

Philip
 
G

Guest

(via Instant VB):
Delegate Sub ShowProgressDelegate(ByVal pi As String, ByVal totalDigits As
Integer, ByVal digitsSoFar As Integer, <System.Runtime.InteropServices.Out()>
ByRef cancel As Boolean)

Private Sub ShowProgress(ByVal pi As String, ByVal totalDigits As Integer,
ByVal digitsSoFar As Integer, <System.Runtime.InteropServices.Out()> ByRef
cancel As Boolean)

'....

'INSTANT VB NOTE: The local variable showProgress was renamed since Visual
Basic will not allow local variables with the same name as their method:
Dim showProgress_Renamed As ShowProgressDelegate = New
ShowProgressDelegate(AddressOf Me.ShowProgress)
Dim inoutCancel As Object = False ' Avoid boxing and losing our return value

' Show progress synchronously (so we can check for cancel)
'Invoke(showProgress, new object[] { pi, totalDigits, digitsSoFar,
inoutCancel});
cancel = CBool(inoutCancel)

' Show progress asynchronously
BeginInvoke(showProgress_Renamed, New Object() { pi, totalDigits,
digitsSoFar, inoutCancel})

'....

End Sub
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter
 
G

Guest

Slight correction - VB does allow local variables with the same name as the
method:

Delegate Sub ShowProgressDelegate(ByVal pi As String, ByVal totalDigits As
Integer, ByVal digitsSoFar As Integer, <System.Runtime.InteropServices.Out()>
ByRef cancel As Boolean)

Private Sub ShowProgress(ByVal pi As String, ByVal totalDigits As Integer,
ByVal digitsSoFar As Integer, <System.Runtime.InteropServices.Out()> ByRef
cancel As Boolean)

'....

Dim showProgress As ShowProgressDelegate = New
ShowProgressDelegate(AddressOf Me.ShowProgress)
Dim inoutCancel As Object = False ' Avoid boxing and losing our return value

' Show progress synchronously (so we can check for cancel)
'Invoke(showProgress, new object[] { pi, totalDigits, digitsSoFar,
inoutCancel});
cancel = CBool(inoutCancel)

' Show progress asynchronously
BeginInvoke(showProgress, New Object() { pi, totalDigits, digitsSoFar,
inoutCancel})

'....

End Sub
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter


David Anton said:
(via Instant VB):
Delegate Sub ShowProgressDelegate(ByVal pi As String, ByVal totalDigits As
Integer, ByVal digitsSoFar As Integer, <System.Runtime.InteropServices.Out()>
ByRef cancel As Boolean)

Private Sub ShowProgress(ByVal pi As String, ByVal totalDigits As Integer,
ByVal digitsSoFar As Integer, <System.Runtime.InteropServices.Out()> ByRef
cancel As Boolean)

'....

'INSTANT VB NOTE: The local variable showProgress was renamed since Visual
Basic will not allow local variables with the same name as their method:
Dim showProgress_Renamed As ShowProgressDelegate = New
ShowProgressDelegate(AddressOf Me.ShowProgress)
Dim inoutCancel As Object = False ' Avoid boxing and losing our return value

' Show progress synchronously (so we can check for cancel)
'Invoke(showProgress, new object[] { pi, totalDigits, digitsSoFar,
inoutCancel});
cancel = CBool(inoutCancel)

' Show progress asynchronously
BeginInvoke(showProgress_Renamed, New Object() { pi, totalDigits,
digitsSoFar, inoutCancel})

'....

End Sub
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: C#/VB to Python converter


Philip said:
Hi,

I am trying to follow some MSDN articles on multi-threading as I need to
tryu and do it, but I am working in VB.NET and the articleas are in c#.

The articles are here: http://msdn2.microsoft.com/en-us/library/ms951089.aspx

In c# I have this code that works

delegate void ShowProgressDelegate(string pi, int totalDigits, int
digitsSoFar, out bool cancel);

void ShowProgress(string pi, int totalDigits, int digitsSoFar, out bool
cancel)
{

....

ShowProgressDelegate showProgress = new ShowProgressDelegate(ShowProgress);
object inoutCancel = false; // Avoid boxing and losing our return value

// Show progress synchronously (so we can check for cancel)
//Invoke(showProgress, new object[] { pi, totalDigits, digitsSoFar,
inoutCancel});
cancel = (bool)inoutCancel;

// Show progress asynchronously
BeginInvoke(showProgress, new object[] { pi, totalDigits, digitsSoFar,
inoutCancel});

....

}

how do I do that in VB.NET please?

I tried this below but it shows a compile error:
Delegate Sub ShowProgressDelegate(ByVal dblPctDone As Integer, ByVal
iMax As Integer, ByRef bCancel As Boolean)

Private Sub cmdExecute_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdExecute.Click

Dim ShowProgress As New ShowProgressDelegate(AddressOf ShowProgress())

thanks for any help

Philip
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top