如何执行System.Threading.Task作为两个或更多其他任务结果的延续?
public Task<FinalResult> RunStepsAsync()
{
Task<Step1Result> task1 = Task<Step1Result>.Factory.StartNew(Step1);
// Use the result of step 1 in steps 2A and 2B
Task<Step2AResult> task2A = task1.ContinueWith(t1 => Step2A(t1.Result));
Task<Step2BResult> task2B = task1.ContinueWith(t1 => Step2B(t1.Result));
// Now merge the results of steps 2A and 2B in step 3
Task<FinalResult> task3 = task2A
.ContinueWith(
t2A => task2B.ContinueWith(
t2B => Step3(t2A.Result, t2B.Result)))
.Unwrap();
return task3;
}
Run Code Online (Sandbox Code Playgroud)
这样可行,但是双重ContinueWith似乎效率低下.有没有更好的方法来实现这一点,也许使用TaskCompletionSource?(我不想使用锁或Task.WaitAll.)
Can Castle Windsor可以解析由字符串参数过滤的集合吗?
interface IViewFactory
{
IView[] GetAllViewsInRegion(string regionName);
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序将区域定义为IView派生类型的组.当我在运行时显示特定区域时,我想要解析其中每个IView类型的实例(la Prism).
我尝试过使用Castle的Typed Factory Facility,ComponentModel Construction Contributors和Handler Selectors,但是我无法弄清楚如何以Castle可以访问的方式将多个类型映射到字符串,也不知道如何将Castle扩展到在确定要尝试解析哪些类型并在容器中返回时检查字符串.
在生产(发布)版本中启用静态代码分析时是否存在任何性能成本?
我们的CI服务器在C#项目的调试版本上运行代码分析,而发布版本禁用静态代码分析(即未定义CODE_ANALYSIS).如果没有理由在生产版本上禁用代码分析,那么我就是在浪费时间进行调试构建.
反射器向我显示,SuppressMessage如果禁用代码分析,则排除属性,但我不希望额外属性影响运行时性能.这是启用静态代码分析的唯一效果(在Visual Studio 2013中)吗?
Microsoft 在编写安全高效的 C# 代码中建议:
将
in修改器应用于readonly struct大于的参数System.IntPtr.Size
有没有一种简单的方法来检查像这样的引用结构的托管内存大小ReadOnlySpan<byte>?
以下方法不起作用:
// CS0208 Cannot get the size of a managed type
unsafe { size = sizeof(ReadOnlySpan<byte>); }
// CS0306 The type 'ReadOnlySpan<byte>' may not be used as a type argument
size = Marshal.SizeOf(default(ReadOnlySpan<byte>));
// ArgumentException "must not be a generic type definition"
size = Marshal.SizeOf(typeof(ReadOnlySpan<byte>));
Run Code Online (Sandbox Code Playgroud)