So i have a method that does an invoke on a datagridview and works fine for the first thread that runs it, however when a second thread tries to utilise the method, the download part of it still functions, however the invoke statement stops working for the first thread and starts to change both
public void ByteTransferResume(int indexResume)
{
HttpWebRequest req;
HttpWebResponse resp;
req = (HttpWebRequest)HttpWebRequest.Create(FileLocationName);
req.AddRange((int)fileInfoDestination.Length);
resp = (HttpWebResponse)(req.GetResponse());
long fileLength = resp.ContentLength;
FileLocationLength = fileLength;
using (Stream responseStream = resp.GetResponseStream())
{
int iBufferSize = 1024;
iBufferSize *= 1000;
using (FileStream saveFileStream = new FileStream(FileDestination, FileMode.Append, FileAccess.Write, FileShare.ReadWrite))
{
int iByteSize;
byte[] downBuffer = new byte[iBufferSize];
while ((iByteSize = responseStream.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
saveFileStream.Write(downBuffer, 0, iByteSize);
FileInfo fileInfoDestinations = new FileInfo(FileDestination);
FileDestinationLength = (int)fileInfoDestinations.Length;
double downloadProgress = ((double)FileDestinationLength / FileLocationLength) * 100;
// MessageBox.Show(downloadProgress.ToString());
dgvDownloadInfo.Invoke(new dgvCommandDelegate(DGVCommand), new object[] { $"UPDATE Download_Info SET [Progress] = '{downloadProgress:F2}%' WHERE [File Name] = '{thread1[indexResume].Name}'" });
//MessageBox.Show(thread1[indexResume].Name);
//MessageBox.Show(indexResume.ToString());
// dgvDownloadInfo.Invoke(new dgvConnectionDelegate(DGVConnection));
Thread.Sleep(10);
}
}
}
}