zl程序教程

您现在的位置是:首页 >  后端

当前栏目

C# BeginInvoke EndInvoke获取返回值

c# 获取 返回值
2023-09-14 09:10:47 时间
Func<string, string[]> f = t =>
                {
                	//在此会卡住ftp响应不过来 会等待
                    WebResponse response = reqFTP.GetResponse();
                    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
                    {
                        string line = null;
                        while (reader != null && (line = reader.ReadLine()) != null)
                        {
                            if (line.IndexOf("<DIR>") == -1)
                            {
                                //result.Append(Regex.Match(line, @"[\S]+ [\S]+", RegexOptions.IgnoreCase).Value.Split(' ')[1]);
                                //result.Append("\n");
                            }
                            result.Append(line);
                            result.Append("\n");
                        }
                        if (result.ToString().Length > 0)
                            result.Remove(result.ToString().LastIndexOf('\n'), 1);
                    }
                    response?.Close();
                    return result.ToString().Split('\n');
                };
                IAsyncResult res = f.BeginInvoke(null, null, null);
                string[] lists = f.EndInvoke(res);
                Console.WriteLine(lists.Length);