|
-
Dec 18th, 2011, 10:50 AM
#1
Thread Starter
New Member
c# to vbnet delegate
Hi Ive been trying to translate part of a code using this websites :
http://www.developerfusion.com/tools.../csharp-to-vb/
http://converter.telerik.com/
But I could not make it work specially this part :
Code:
bw.DoWork += delegate(object sender2, DoWorkEventArgs e2)
{
_lastImageUploadDetails = uploader.UploadImage(txtFilePath.Text, resizeWidth, resizeHeight);
};
This is the source I would like you to help me out :
Code:
bw.DoWork += delegate(object sender2, DoWorkEventArgs e2)
{
_lastImageUploadDetails = uploader.UploadImage(txtFilePath.Text, resizeWidth, resizeHeight);
};
bw.RunWorkerAsync();
// when the background worker is finished, run this anonymous method which either updates
// the details of the last uploaded image or displays an appropriate error message
// if there were problems.
bw.RunWorkerCompleted += delegate(object sender3, RunWorkerCompletedEventArgs e3)
{
try
{
if (e3.Error != null)
{
throw e3.Error;
}
UpdateLastUploadedImageDisplayDetails(_lastImageUploadDetails); txtInfo.Text = "Image Uploaded.";
}
catch (FileNotFoundException exp)
{
txtInfo.Text = exp.Message;
}
catch (XmlException exp)
{
txtInfo.Text = exp.Message;
}
};
So please if anybody here knows some c# and vbnet if he could do it I will really appreciate it.
Regards.
-
Dec 18th, 2011, 12:44 PM
#2
Re: c# to vbnet delegate
Is this what you mean?
vb.net Code:
Private Sub bw_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles bw.DoWork
_lastImageUploadDetails = uploader.UploadImage(txtFilePath.Text, resizeWidth, resizeHeight)
End Sub
Private Sub bw_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles bw.RunWorkerCompleted
Try
If e.Error IsNot Nothing Then
Throw (e.Error)
End If
UpdateLastUploadedImageDisplayDetails(_lastImageUploadDetails)
txtInfo.Text = "Image Uploaded."
Catch exp As FileNotFoundException
txtInfo.Text = exp.Message
Catch exp As XmlException
txtInfo.Text = exp.Message
End Try
End Sub
-
Dec 18th, 2011, 08:22 PM
#3
Re: c# to vbnet delegate
For VB10 - VS 2010 (in earlier versions of VB, this is not nearly as clean, but VB10 has 'Sub' lambdas):
Code:
AddHandler bw.DoWork, Sub(sender2 As Object, e2 As DoWorkEventArgs) _lastImageUploadDetails = uploader.UploadImage(txtFilePath.Text, resizeWidth, resizeHeight)
bw.RunWorkerAsync()
' when the background worker is finished, run this anonymous method which either updates
' the details of the last uploaded image or displays an appropriate error message
' if there were problems.
AddHandler bw.RunWorkerCompleted, Sub(sender3 As Object, e3 As RunWorkerCompletedEventArgs)
Try
If e3.Error IsNot Nothing Then
Throw e3.Error
End If
UpdateLastUploadedImageDisplayDetails(_lastImageUploadDetails)
txtInfo.Text = "Image Uploaded."
Catch exp As FileNotFoundException
txtInfo.Text = exp.Message
Catch exp As XmlException
txtInfo.Text = exp.Message
End Try
End Sub
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|