I'm new to Silverlight and I have created a silverlight application to resize and upload images. The problem is the scroll bar doesn't update until the file has finished uploading. I have included sample code of the PushData function and the event handler. Please someone tell me what I'm doing wrong this problem is driving me crazy.
void btnTotalSizes_Click(object sender, RoutedEventArgs e)
{
// ...
UriBuilder ub = new UriBuilder("http://localhost:21636/FileReceiver.ashx");
WebClient wc = new WebClient();
wc.OpenWriteCompleted += (s2, e2) =>
{
PushData(outStream, e2.Result);
e2.Result.Close();
outStream.Close();
};
wc.OpenWriteAsync(ub.Uri);
}
private static void PushData(Stream input, Stream output)
{
byte[] buffer = new byte[4096];
int bytesRead = 0;
int tempTotal = 0;
while ((bytesRead = input.Read(buffer, 0, buffer.Length)) != 0)
{
output.Write(buffer, 0, bytesRead);
tempTotal += bytesRead;
_uploadProg++;
int percentDone = (int)(
((decimal)tempTotal / (decimal)input.Length) * 100);
ProgressUpdated(null, new UploadProgressChangedEventArgs(percentDone));
}
}
void MainPage_ProgressUpdated(object sender, UploadProgressChangedEventArgs e)
{
progFileProg.Maximum = 100;
progFileProg.Value = e.ProgressPercentage;
sbUpdateProg.Begin();
}