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);
C# BeginInvoke EndInvoke获取返回值
最新推荐文章于 2023-09-23 13:32:58 发布