C# to VB

M

Mike

Have a C# example for async delegate and need to convert to VB. Have
everthing figured out except one statement.

LoadDataSetHandler dl = (LoadDataSetHandler)
((AsyncResult)ar).AsyncDelegate;

The closest i came to it:

Dim dl as LoadDataSetHandler = New LoadDataSetHandler _
(AddressOf (AsyncResults)ar.AsyncDelegate)

Problem with this statement: Comma, ')', or a valid expression
continuation expected.

I've tried several variations but can't seem to get it.
Any thoughts?

Included some more of the C# code just in case

private void AsyncTesterForm_Load(object sender, System.EventArgs e)
{
_ConnectionString = ConfigurationSettings.
AppSettings["Data.ConnectionString"];
_TableNames = ConfigurationSettings.
AppSettings["Data.TableNames"].Split(","[0]);

DataManagement dm = new DataManagement();
LoadDataSetHandler dl = new LoadDataSetHandler(dm.GetDataSet);
AsyncCallback asyncCB = new AsyncCallback(this.DataLoaded);
IAsyncResult ar = dl.BeginInvoke
(_ConnectionString, _TableNames, asyncCB, null);
}

private void DataLoaded(IAsyncResult ar)
{
LoadDataSetHandler dl = (LoadDataSetHandler)
((AsyncResult)ar).AsyncDelegate;
_DataSet = dl.EndInvoke(ar);

MethodInvoker mi = new MethodInvoker(this.UpdateUI);
try
{
this.BeginInvoke(mi);
}
catch{}
}
 
M

Mike

That solved one problem but created a new one.
The new error is saying that since dl is a delegate type it can only
take one addressof argument. Is there a difference between C# and VB
that doesn't allow this?
The wonderful world of programming :)
 
S

Scott M.

I am not too familiar with delegate types, but it makes sense that only one
addressOf should be allowed.
 
C

Cor Ligthert [MVP]

Rico,

Be aware that there where in some cases delegates needed in C# these are not
needed in VBNet because of the nature of VBNet. Maybe can you tell what you
want to achieve instead of translating your program 1:1.

You will not be the first who create a bad performing program because of
that.

I hope this helps,

Cor
 
M

Miha Markic [MVP C#]

Hi Mike,

Try this:
Dim dl As new LoadDataSetHandler (AddressOf AsyncResults)
or just
Dim dl As LoadDataSetHandler = AddressOf AsyncResults
 

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