swapyonubuntu
swapyonubuntu

Reputation: 2110

Progressbar in Windows Phone 8.1

I am trying to make my progressbar work in Windows phone 8.1.

Here is my code :

 using (var writeStream = await newZipFile.OpenAsync(FileAccessMode.ReadWrite))
                    {
                        using (var outputStream = writeStream.GetOutputStreamAt(0))
                        {
                            using (var dataWriter = new DataWriter(outputStream))
                            {
                                using (Stream input = webResponse.GetResponseStream())
                                {
                                    long totalSize = 0;
                                    int read;

                                    uint zeroUint = Convert.ToUInt32(0);
                                    uint readUint;

                                    while ((read = input.Read(buffer, 0, buffer.Length)) >0)
                                    {
                                        // totalSize += read;
                                        totalSize = totalSize + read;
                                        //pb2.Value = totalSize * 100 / sizeFit;
                                        await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                        {
                                            //Declaration of variables
                                            // load.progresschanged(totalSize * 100 / sizeFit);
                                            pb2.Value = totalSize * 100 / sizeFit;




                                        });

                                        readUint = Convert.ToUInt32(read);
                                        IBuffer ibuffer = buffer.AsBuffer();
                                        dataWriter.WriteBuffer(ibuffer, zeroUint, readUint);
                                    }

                                    await dataWriter.StoreAsync();
                                    await outputStream.FlushAsync();
                                    dataWriter.DetachStream();
                                }
                            }
                        }
                    }

The problem here is that progressbar updates only when the value is 100. Any help appreciated.

Upvotes: 2

Views: 88

Answers (1)

Jerin
Jerin

Reputation: 4299

1)Make sure the maxvalue of progressbar is 100 in view.
2) pb2.Value = sizeFit * 100 / totalSize; Might be you are calculating the percentage wrong. Since I am not able to find sizeFit value in your code why not place a breakpoint and check whats the value being returned

Upvotes: 2

Related Questions