Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Ive been trying to translate part of a code using this websites :
http://www.developerfusion.com/tools/convert/csharp-to-vb/[^]
http://converter.telerik.com/[^]
But I could not make it work specially this part :

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 :


C#
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.
Posted

1 solution

Why aren't you using the standard event handler construct?

C#
backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);


Yielding:

C#
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    // Get the BackgroundWorker that raised this event.
    BackgroundWorker worker = sender as BackgroundWorker;

    // Assign the result of the computation
    // to the Result property of the DoWorkEventArgs
    // object. This is will be available to the
    // RunWorkerCompleted eventhandler.

    // e.Result = result of some action;
}


At that point, the translator should work just fine...
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 18-Dec-11 12:35pm    
That was my idea to try it, too. My 5. (But did you try it?)
--SA
#realJSOP 18-Dec-11 13:08pm    
Whenever I use a background worker, that's the way I do it. It's standard C# (nothing fancy or obscure). I don't use the telerik converter, but if it can't handle standard .Net constructs, many everyone else should avoid it, too.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900