I'm trying to save an attachment I get from a byte[] from a webservice. The problem is that my code continues even before the completed event of the method could have been called. Is there some way to let the application wait for that event.
This is the part where I save the attachment as byes:
var temporaryStream = new MemoryStream();
foreach (var attachment in msg.Attachments.Where(attachment =>
attachment.FileName.Equals(attachmentName)))
{
attachment.Save(temporaryStream);
}
return temporaryStream.ToArray();
And this is how I try to get the byte[]:
byte[] result = null;
try
{
_popClient.SaveAttachmentCompleted += (sender, e) =>
{
if (e.Error != null) return;
result = e.Result;
};
_popClient.SaveAttachmentAsync(uniqueId, attachmentName);
return result;
}
The Async call takes to long to finish... Is there any way to speed the process of fetching the attachment up or another way to fix that problem?