小编Ami*_*tan的帖子

为所有线程设置默认线程文化?

可能重复:
设置应用程序的CurrentCulture和CurrentUICulture

我想为我在应用程序中打开的每个线程设置默认文化.有没有办法设置它(不单独在每个线程上设置它)

谢谢

c# multithreading

15
推荐指数
2
解决办法
2万
查看次数

C#懒惰执行+内存理解

你可以告诉我在执行以下代码时内存中发生了什么:

情况1:

public static void Execute()
{
    foreach(var text in DownloadTexts())
    {
          Console.WriteLine(text);
    }
}


public static IEnumerable<string> DownloadTexts()
{
     foreach(var url in _urls)
     {
         using (var webClient = new WebClient())
         {
              yield return webClient.DownloadText(url);
         }
     }
}
Run Code Online (Sandbox Code Playgroud)

让我们假设在第一次迭代后我得到html1.

什么时候从内存中清除html1?

  1. 在下一次迭代?
  2. 当foreach结束?
  3. 当功能结束?

谢谢

**编辑**

案例2:

public static void Execute()
{
    var values = DownloadTexts();
    foreach(var text in values)
    {
          Console.WriteLine(text);
    }
}


public static IEnumerable<string> DownloadTexts()
{
     foreach(var url in _urls)
     {
         using (var webClient = new WebClient())
         { …
Run Code Online (Sandbox Code Playgroud)

c# memory lazy-evaluation yield-return

2
推荐指数
1
解决办法
251
查看次数