help converting to vb.net

Apr 7, 2009 at 4:14 AM
Edited Apr 7, 2009 at 4:20 AM
I am struggling to write the event handler for percent done in vb.net.  Could anyone take a stab and help?
i have tried to use the converters on the web and they bug out.
specifically, i am trying to convert this piece from the example code:

tmp.FileCompressionStarted += new EventHandler<FileInfoEventArgs>((s, e) =>
{
    Console.WriteLine(String.Format("[{0}%] {1}",
    e.PercentDone, e.FileInfo.Name));
}); 
 


Thanx in advance,
Matt

Apr 15, 2009 at 5:37 PM
I took a shot at trying to convert the code as well, and got stuck on the same point as you.

Apparently, vb.net doesn't support anonymous event delegates in the way that c# does,
 at least I haven't been able to get them converted to an acceptable vb.net syntax.

The article at this link has some discussion of lambda event handlers in vb.net,
  but I still haven't been able to figure out how to convert those sections of the code.

http://stackoverflow.com/questions/204801/how-to-declare-lambda-event-handlers-in-vb-net

Maybe some c# guru has the answer. Anyone?

Coordinator
Apr 15, 2009 at 7:49 PM
You absolutely don't have to use any lambda. Consider this alternative C# code:

[your method]
tmp.FileCompressionStarted += new EventHandler<FileInfoEventArgs>(tmp_FileCompressionStarted);

[method outside yours]
static void tmp_FileCompressionStarted(object sender, FileInfoEventArgs e)
{
        //place event code here
}