如何在Windows应用程序中绑定来自Task.Factory.StartNew的控件

时间:2014-11-27 13:24:39

标签: c# winforms windows-applications

我使用套接字编程异步将文件从客户端传输到服务器。但是我希望在完成运行任务后绑定 datagridview 控件。

我的表格左侧有客户列表,剩下的表格我显示所选的客户端文件列表(从左角选择客户端),当我从客户端到服务器的文件传输时,它已正确传输并立即绑定此将文件传输到右角DataGridView控件使用异步方法的文件名和路径问题从此处开始,我无法绑定此网格控件。

先谢谢.....

以下是我的代码:

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

0 个答案:

没有答案