小编sno*_*ode的帖子

为什么要使用continueWith而不是简单地将延续代码附加到后台任务的末尾?

msdn文档Task.ContinueWith只有一个代码示例,其中一个任务(dTask)在后台运行,后跟(使用ContinueWith)第二个任务(dTask2).样品的本质如下所示;

  Task dTask = Task.Factory.StartNew( () => {
                        ... first task code here ...
                        } ); 

  Task dTask2 = dTask.ContinueWith( (continuation) => {
                       ... second task code here ...
                      } );                      
  Task.WaitAll( new Task[] {dTask, dTask2} );
Run Code Online (Sandbox Code Playgroud)

我的问题很简单; 使用.ContinueWith调用第二个代码块的优点是什么,而不是简单地将它附加到第一个代码块,后者已经在后台运行并将代码更改为这样的代码?

  Task dTask = Task.Factory.StartNew( () => {
                        ... first task code here ...
                        if (!cancelled) //and,or other exception checking wrapping etc
                            {
                             ... second task code here ...
                            }
                        } ); 

  Task.Wait(dTask);
Run Code Online (Sandbox Code Playgroud)

在建议的修订版中,ContinueWith完全避免调用,第二个代码块仍然在后台运行,加上没有上下文切换代码来访问闭包的状态......我不明白?感觉有点愚蠢,我做了一些谷歌搜索,也许只是没有找到正确的短语来搜索.

更新: Hans Passant发布了更多MSDN …

.net c# task task-parallel-library

10
推荐指数
1
解决办法
2834
查看次数

如何从 Azure 命令“powershell 中的 az group list”的“结果”数组中只选择一个属性?

我正在尝试从az group listpowershell 中的 Azure 命令返回的“结果”(对象?)数组中仅选择一个属性?

我知道这听起来微不足道,但这就是奇怪的地方,我希望有一个简单的解释。

如果我运行 Azure 命令az group list -o table(在我使用成功登录后az login),我会得到以下典型响应

PS src> az group list -o table             
Name              Location    Status
----------------  ----------  ---------
group0            westeurope  Succeeded
group1            westeurope  Succeeded
group2            uksouth     Succeeded
group3            westeurope  Succeeded
group4            westeurope  Succeeded
group5            westeurope  Succeeded
group6            westeurope  Succeeded
group7            uksouth     Succeeded
group8            westeurope  Succeeded
group9            westeurope  Succeeded
Run Code Online (Sandbox Code Playgroud)

但是,如果我尝试Name通过执行仅选择属性

az 组列表 | 选择 -p 名称

然后我得到大约 2 个充满空行的屏幕,没有显示任何内容。那么问题来了,上面的命令有什么问题?我应该如何修复它?

我尝试了以下实验来深入研究返回的对象的确切类型,并得到一些我不明白的结果。我希望这对拥有更多 Azure 和 Powershell …

powershell azure

3
推荐指数
2
解决办法
1796
查看次数

为什么我不能使用HashSet <string>来实现IEnumerable <string>接口属性?

我想知道为什么我不能HashSet<string>用来实现IEnumerable<string>接口属性?

下面的代码给出了一个编译错误,出现以下错误;

'Lookups'没有实现接口成员'ILookups.LastNames'.'Lookups.LastNames'无法实现'ILookups.LastNames',因为它没有匹配的返回类型'System.Collections.Generic.IEnumerable'.

public interface ILookups
{
    IEnumerable<string> FirstNames { get; set; }
    IEnumerable<string> LastNames { get; set; }
    IEnumerable<string> Companies { get; set; }
}

public class Lookups : ILookups
{
    public HashSet<string> FirstNames { get; set; }
    public HashSet<string> LastNames { get; set; }
    public HashSet<string> Companies { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

根据Resharper的说法,这是构造函数的签名HashSet; ...

// Type: System.Collections.Generic.HashSet`1
// Assembly: System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// Assembly location: C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Core.dll
...
  /// <summary>
  /// Represents …
Run Code Online (Sandbox Code Playgroud)

c# interface hashset

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

标签 统计

c# ×2

.net ×1

azure ×1

hashset ×1

interface ×1

powershell ×1

task ×1

task-parallel-library ×1