优化记录-day1

1、str.Split('|');改为str.Split(new char[]{'|'});

2、string.format改为StringBuilder

3、优先判断异常情况

Parallel.ForEach(list, async item =>

{

    var result = await Test();

    Console.WriteLine("线程" + result.ToString());

});

public static async Task<string> Test()

{

    return await Task.Run(() =>

      {

          Thread.Sleep(2000);

          Console.WriteLine("Test()方法里面线程ID: {0}", Thread.CurrentThread.ManagedThreadId);

          Console.WriteLine("执行时间:" + DateTime.Now.ToString());

          return Thread.CurrentThread.ManagedThreadId.ToString();

      });

}

你可能感兴趣的:(工作记录,servlet,html,前端)