locked
Help with statement lambda RRS feed

  • Question

  • In the code below, ws.InsertFile is a RIA web service which has to be called asynchronously.

     foreach (FileInfo attachment in ListOfAttachments.Items)
     {
       FileStream fs = attachment.OpenRead();
       byte[] bytes = new byte[fs.Length];
       fs.Read(bytes, 0, (int)fs.Length);
       fs.Close();
       ws.InsertFileCompleted += (s1, e1) => {
          if (string.IsNullOrEmpty(e1.Result))
            filesInsertedSuccessfully++;
          else
            Debug.WriteLine("Error: " + attachment.Name);
         };
       ws.InsertFileAsync(...,...,...,...);
    }

    My question is on the Debug.WriteLine line: will the correct instance of attachment be the one that will be referenced?  For example, if the fifth attachment causes an error, will Debug.WriteLine be referencing the fifth attachment object?

    Thanks.

    Thursday, May 20, 2010 4:33 AM

Answers