0

I am Transfer file from Client to server using Socket Programming asynchronously. But I want to bind datagridview control after completion of running task.

I have form with Client list in left corner and in the remaining form i am showing the selected client file list (selected client from left corner) , when i am File transfer from client to server it was transferred properly and immediately bind this transferred file to right corner DataGridView control With File Name and Path from async method issue start here at time i can not bind this grid control.

Thanks in Advance.....

Below is my Code :

public void collectFileFromClientSocket(string ClientIpAddr, string clientLogDir)
    {
        try
        {
            Task task ; 
            var cts = new CancellationTokenSource();
            ServerSideSocketProgramming serversocketProg = new ServerSideSocketProgramming();
            ModFunctions modFunc = new ModFunctions();
            Common.ModWipeOut modWipeOut = new Common.ModWipeOut();
            RegistryKey regKey = modFunc.DefineRegistryKey(Common.ModWipeOut.WipeOutRegistryPATH, false);
            int port = int.Parse(modWipeOut.Decrypt(modFunc.ReadRegistry(modWipeOut.Encrypt(Common.ModWipeOut.PortNumber), regKey)));// 
            string logCommonFolder = modFunc.ReadRegistry(Common.ModWipeOut.LogReportFolderPath, regKey);// @"E:\";               
            string CreateLocalSysIPDirOnServer = logCommonFolder + "\\";
            if (!Directory.Exists(CreateLocalSysIPDirOnServer))
                Directory.CreateDirectory(CreateLocalSysIPDirOnServer);
            // Call Client from IP Address
            serversocketProg.CallClient(ClientIpAddr, port);

            //Transferring file from Client to Server
            Task.Factory.StartNew(() => serversocketProg.HandleIncomingFile(port, CreateLocalSysIPDirOnServer)
            ).ContinueWith(t=>
            //Fill the DataGridView Method, but not bind the DataGridView control
            fillLogFileInGrid(clientLogDir));               

        }
        catch (Exception ex)
        {
            //MessageBox.Show(ex.ToString());
        }
}
  • Windows Forms application – user1997321 Nov 27 '14 at 13:31
  • So, what's the problem you face? What happens when you run this code? – Sriram Sakthivel Nov 27 '14 at 13:39
  • http://stackoverflow.com/questions/4928195/c-sharp-windows-forms-application-updating-gui-from-another-thread-and-class – macpak Nov 27 '14 at 13:42
  • look , @SriramSakthivel i have updated my question . – user1997321 Nov 27 '14 at 14:12
  • Your edit says nothing helpful. What is the error you get? `InvalidOperationException` ? – Sriram Sakthivel Nov 27 '14 at 14:14
  • I need to bind DataGridView control from async task method and this was not happen in my code. – user1997321 Nov 27 '14 at 14:25
  • Ok, that's not happening, instead say what happens? Any runtime exception? Or what? Without knowing what is the problem, our answers will have to make assumptions, that won't work well all the time. – Sriram Sakthivel Nov 27 '14 at 14:29
  • It is not clear what you are asking. There's not a good code example, nor a precise description of what happens that you don't want to happen, and how that's different from what you do want to happen. Some other thoughts: why doesn't this use `async`/`await`? What's the point of the `Task task;` local variable? Why do you do some network I/O asynchronously, but apparently not all? – Peter Duniho Nov 27 '14 at 18:46

0 Answers0