Click here to Skip to main content
15,896,726 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am Transfer file from Client to server using Socket Programming asynchronously. But I want to bind datagridview control after completion of running task.

Thanks in Advance.....

Below is my Code :

C#
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());
          }
  }
Posted

1 solution

Try like below
C#
var task1 = new Task(() =>
           {
               serversocketProg.HandleIncomingFile(port, CreateLocalSysIPDirOnServer)
           });
Task task2 = task1.ContinueWith(antecedent =>
                                               {
                                                   fillLogFileInGrid(clientLogDir);
                                               }, TaskScheduler.FromCurrentSynchronizationContext()

               );
           task1.Start(TaskScheduler.FromCurrentSynchronizationContext());

Hope this helps
 
Share this answer
 
Comments
Jadhav Gangadhar 27-Nov-14 9:39am    
Thanks....I have already tried this but not worked.
Jameel VM 27-Nov-14 23:57pm    
any exception?
Jadhav Gangadhar 28-Nov-14 0:49am    
no exception.... My async method working as expected but i want to call fill grid control method from that async method. But i am getting nothing.

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