Help with C# to VB.Net Conversion

D

Daniel Jeffrey

Hello,
I am a C# developer and am now starting to do some work in VB.NET and for
the life of me cant get something working the way I cant.

If anyone can offer any suggestions on how to convert this c# into Working
VB.Net code that would be great.

C# Class to be converted to VB.Net

I cant seem to get this line to work > FireAsync(Completed, this,
EventArgs.Empty);


Class........

public event EventHandler Completed;
...
...
...
private void someMethod()
{
FireAsync(Completed, this, EventArgs.Empty);
}


protected void FireAsync(Delegate dlg, params object[] pList)
{
if (dlg != null)
{
Target.BeginInvoke(dlg, pList);
}
}

end class



VB.Net calling Code

Public MustInherit Class GridData
Inherits AsyncUtilities.AsyncOperation

AddHandler mobjData.Completed, AddressOf DataLoad_Finished
AddHandler mobjData.Cancelled, AddressOf DataLoad_Cancelled
AddHandler mobjData.Failed, New
System.Threading.ThreadExceptionEventHandler(AddressOf DataLoad_Failed)
 
D

Daniel Jeffrey

This produces the same result I got when I did it myself

'Public Event Completed(sender As Object, e As System.EventArgs)' is an
event, and cannot be called directly. Use a 'RaiseEvent' statement to raise
an event.


Andy B said:
http://converter.telerik.com/


Daniel Jeffrey said:
Hello,
I am a C# developer and am now starting to do some work in VB.NET and for
the life of me cant get something working the way I cant.

If anyone can offer any suggestions on how to convert this c# into Working
VB.Net code that would be great.

C# Class to be converted to VB.Net

I cant seem to get this line to work > FireAsync(Completed, this,
EventArgs.Empty);


Class........

public event EventHandler Completed;
...
...
...
private void someMethod()
{
FireAsync(Completed, this, EventArgs.Empty);
}


protected void FireAsync(Delegate dlg, params object[] pList)
{
if (dlg != null)
{
Target.BeginInvoke(dlg, pList);
}
}

end class



VB.Net calling Code

Public MustInherit Class GridData
Inherits AsyncUtilities.AsyncOperation

AddHandler mobjData.Completed, AddressOf DataLoad_Finished
AddHandler mobjData.Cancelled, AddressOf DataLoad_Cancelled
AddHandler mobjData.Failed, New
System.Threading.ThreadExceptionEventHandler(AddressOf DataLoad_Failed)
 
A

Armin Zingler

Daniel Jeffrey said:
This produces the same result I got when I did it myself

'Public Event Completed(sender As Object, e As System.EventArgs)' is an
event, and cannot be called directly. Use a 'RaiseEvent' statement to
raise
an event.

VB does something under the hood. The implicitly declared delegate is called
CompletedEventHandler and the instance is called CompletedEvent. So, try
passing 'CompletedEvent', not 'Completed', if a Delegate is expected.
Untested.


Armin
 
D

Daniel Jeffrey

thanks this worked.

Who ever said C# and VB.Net are "fundamentally" the same, never moved from 1
to the other

Dan
 
A

Andy B

Yea. I found problems with that converter now that I looked at it. I
converted some base classes for custom providers and it broke the code.


Daniel Jeffrey said:
This produces the same result I got when I did it myself

'Public Event Completed(sender As Object, e As System.EventArgs)' is an
event, and cannot be called directly. Use a 'RaiseEvent' statement to
raise
an event.


Andy B said:
http://converter.telerik.com/


message
Hello,
I am a C# developer and am now starting to do some work in VB.NET and
for
the life of me cant get something working the way I cant.

If anyone can offer any suggestions on how to convert this c# into
Working
VB.Net code that would be great.

C# Class to be converted to VB.Net

I cant seem to get this line to work > FireAsync(Completed, this,
EventArgs.Empty);


Class........

public event EventHandler Completed;
...
...
...
private void someMethod()
{
FireAsync(Completed, this, EventArgs.Empty);
}


protected void FireAsync(Delegate dlg, params object[] pList)
{
if (dlg != null)
{
Target.BeginInvoke(dlg, pList);
}
}

end class



VB.Net calling Code

Public MustInherit Class GridData
Inherits AsyncUtilities.AsyncOperation

AddHandler mobjData.Completed, AddressOf
DataLoad_Finished
AddHandler mobjData.Cancelled, AddressOf
DataLoad_Cancelled
AddHandler mobjData.Failed, New
System.Threading.ThreadExceptionEventHandler(AddressOf DataLoad_Failed)
 

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