title: how to calculate the transfer rate speed kb/s SOCKETS c#
body: <p>How to calculate the transfer rate speed in kilobyte per second, i used stopwatch but it doesnt work , because it gives me an error about div on zero ( count / 0)</p>
  
  <pre><code>    public void sendFile(string filePath)
      {
          Stopwatch stopWatch = new Stopwatch();
          FileInfo file = new FileInfo(filePath);
          try
          {
              int fileSize = (int)file.Length;
              Program.mainForm.MaxProgressBarHandler(fileSize);
              byte[] fileDetial;
              string detail =  file.Name + "," + fileSize.ToString();
              fileDetial = Encoding.ASCII.GetBytes(detail);
              client.Send(fileDetial);
              byte[] fileData = new byte[fileSize];
  
              int count;
              int sum = 0;
              file.OpenRead().Read(fileData, 0, fileSize);
              while (sum &lt; fileSize)
              {
                  stopWatch.Restart();
                  if (fileSize - sum &lt; packetSize)
                  {
                      count = client.Send(fileData, sum, fileSize - sum, SocketFlags.None);
                      Program.mainForm.UpdateProgressBarHandler(count);
                  }
                  else
                  {
                      count = client.Send(fileData, sum, packetSize, SocketFlags.None);
                      Program.mainForm.UpdateProgressBarHandler(count);
                  }
                  stopWatch.Stop();
                  sum += count;
                  Program.mainForm.AppendLabel(((fileSize * 8) / stopWatch.ElapsedMilliseconds).ToString());
                  Console.WriteLine(sum + "of" + fileSize + "sent");
              }
          }
          finally
          {
              Console.WriteLine("sent");
              CloseClient();
          }
      }
  </code></pre>
  
  <p>Please help me =)</p>