-2

im Trying to display percentage while uploading file to ftp dosnt work what is missing? this is the code im using

                    {
                    PrgBar.Invoke(
                        (MethodInvoker)delegate
                        {
                            PrgBar.Maximum = (int)fileStream.Length;
                        });

                    byte[] buffer = new byte[10240];
                    int read;
                    while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        ftpStream.Write(buffer, 0, read);
                        PrgBar.Invoke((MethodInvoker)delegate
                        {
                            PrgBar.Value = (int)fileStream.Position;
                            int percent = (PrgBar.Value / PrgBar.Maximum) * 100;
                            **LblPercent.Text = percent.ToString()** + "%"; 
                        });
                    }
                }

tnx for any help :)

Arik m
  • 1
  • 6
    What are you targeting: Winforms, WPF, ASP..? YOU should __always__ TAG your questions correctly so one can see it on the questions page! - Also: _Doesn't work_ is not a helpful problem description! – TaW Nov 13 '21 at 08:51
  • Does this answer your question? [Int division: Why is the result of 1/3 == 0?](https://stackoverflow.com/questions/4685450/int-division-why-is-the-result-of-1-3-0) – Progman Nov 13 '21 at 10:50
  • Also check other questions like https://stackoverflow.com/questions/9288904/division-returns-zero – Progman Nov 13 '21 at 10:51
  • c# winforms vs2022 – Arik m Nov 13 '21 at 18:43

1 Answers1

0

I don't know if you have a problem with the UIThread. But you can handle such things much better if you use BackgroundWorker's.

https://learn.microsoft.com/en-us/dotnet/api/system.componentmodel.backgroundworker?view=net-5.0

EricW
  • 56
  • 3