put in a asynchronous call with a callback

G

Guest

Hi!

I've implemented many times an asynchronous call of a method with a call
backfunction successfully.

But to implement this with VB.NET is not so successfully. I can implement
all events ProcessingEvent, CompletedEvent, etc.
It works fine and copies all files in the background ...

Bit to make it perfekt I want to implement a callback function wich will be
used to do the final work, show the finished message and so on.

With C# I can do that with a BeginInvoke() on the event object. Looks like

callback = new AsyncCallback(CopyCompletion);
DoCopy.BeginInvoke(this, args, callback, args);

But it is not possible to use BeginInvoke in that way in C#.

How can I do that?

Thanks for your help

Gerda
 
P

Phil G.

Hi Gerda,

Fortunately you are mistaken. VB.Net uses the same classes and methods. See
my response to Brad Rogers, dated 13/9/05 (UK date :) and titled Delegates
Help.

I hope that helps.

Rgds, Phil
 
G

Guest

Hi Phil!

Your explanation about the use of delegates ar right!

Maybe my statements were not clear. I want to use the event keyword as
antagonism to the delegate keyword!

Why? I don't want to use delegates because anyone is able to access a public
delegate, can add subscribers to it and can fire the event - as well when
there is no event on the publisher side.
When you use a event only the publisher class can fire the event. Coexistent
anyone can add metods to the delegate list.

That's why I want to use events as reasonable contradistinction to delegates.

But my problem is that it seems to be that you can't use events in VB.NET in
the same way in C#.

When you you use VS.NET and type in C# the '.' behind the event variable you
get with the help of intellisense the whole bunch of methods and properties
you also get with a delegate variable. But when you do that in VB.NET you
receive nothing at all with the help of intellisense. There seems to be no
way to use delegate methods, etc. with events in VB.NET!

I want to implement the BeginInvoke() method to put in an callback methode.
But not on a delegate variable but on a event variable.

How to to that?

here is a little sample code:

public event CopyHandler CopyEvent;

public void RunCopyAsync(object argument)
{
if (DoWork != null) // in VB.NET this is not necessary - it's done
automatically
{
DoCopyEventArgs args = new DoCopyEventArgs(argument);
AsyncCallback callback;
callback = new AsyncCallback(ReportCopyCompletion);
CopyEvent.BeginInvoke(this, args, callback, args);
}
}
 

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