Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a DataGridView which looks like this:

select file1 file2 timeout hostname
checkbox abc.txt bcd.txt 200 SOVIT-PC
chekbox 132.txt xyz.txt 200 DELL-PC

For all the checkboxes selected, i need to create separate threads and send these files to the particular hostname using TCP connection. What we have is the host is already running on a known port and is ready to accept the files.

And the problem is i dont know how to implement this using threads so that the GUI also doesnt freeze and the backgound work of sending the files is also carried out.

Please help with your suggestions!!!
Posted
Comments
gggustafson 19-May-14 10:28am    
You do not mark solutions as the solution. I'll answer your question when you make the committment to do so.
ZurdoDev 19-May-14 16:52pm    
Where are you stuck?

1 solution

I hope the following helps;

C#
foreach(DataGridViewRow row in this.dataGridView.Rows)
{
    string fileName = row.cells[0].value.toString();
    Thread t = new Thread(new ParameterizedThreadStart(UploadFile));
    t.IsBackgroundThread = true;
    t.Start(fileName);

}

public void UploadFile(string uploadFile)
{
   //your code to upload file
}


Hope this helps.

Happy coding..!!

Please mark the answer as correct if this resolves your issue..

Thanks.
 
Share this answer
 
Comments
sovit agarwal 20-May-14 1:58am    
Hi nayan!!
Thanks for your support but just one question...
Does "fileName" here refer to the file that i need to transfer ? Because i need to transfer 2 or more files depending on the checkbox that is selected in the datagridview and for that i need to have an array ...
Nayan Ambaliya 20-May-14 2:10am    
yes, the fileName refers to the file you want to transfer.
In your case if you would like to transfer more than one file, you can have an array as an argument and then do all the logic in the UploadFile function.

Hope this clears.

Please mark the above answer as correct if this has resolved your issue. This helps..!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900