相关疑难解决方法(0)

使用Async和Await进行异步编程

我正在阅读本教程,了解如何在c#中异步编程并遇到错误我不知道如何解决.这是链接:http://msdn.microsoft.com/en-us/library/hh191443.aspx,错误是:

Cannot find all types required by the 'async' modifier.  
Are you targeting the wrong framework version, or missing a reference to an assembly?   
Run Code Online (Sandbox Code Playgroud)

我的目标是.NET 4.0框架,并且不确定是否需要任何其他程序集.

这是代码:

public async Task<string> AccessTheWebAsync(Class1 class1, Class2 class2)
{
  // GetStringAsync returns a Task<string>. That means that when you await the 
  // task you'll get a List<string> (urlContents).
  Task<string[]> listTask = GetList(class1);

  // send message task

  // You can do work here that doesn't rely on the string from GetStringAsync. …
Run Code Online (Sandbox Code Playgroud)

c# .net-4.0 async-await c#-5.0 async-ctp

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

新的C#异步功能是否在编译器中严格实现

作为一名C#程序员,他有兴趣探索"如何工作",我有兴趣了解更多关于使新异步功能工作的过程.

我关注过Eric Lippert关于异步的优秀文章系列:异步博客文章

我不记得在任何地方看到任何对此功能的实现的引用(在高级别),除了"编译器正在为我们完成大部分工作"这一事实.

这个功能严格来说是编译器功能吗?编译器是否以某种方式重写代码,那就是它?还是有其他的东西,如运行时支持,使这种情况发生?

.net c# clr asynchronous async-await

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

异步等待定位4.0部署要求

Microsoft已更新.net 4.0的异步/等待目标,现在建议使用nuget上提供的Microsoft.Bcl.Async库.

在发行说明中,它声明需要具有KB 2468871的 .net 4 .

  1. KB2468871是构建要求还是部署要求?
  2. KB2468871的哪些方面需要它?

.net .net-4.0 targeting async-await c#-5.0

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

为什么带参考汇编的VS2012项目无法自动定位4.0

在Visual Studio 2012 C#控制台应用程序中,我将".NET Framework Target"从4.5降级到4.0.安装了两个框架的Win 7 Pro.

然后我引用一个程序集,通过警告抱怨以下内容:

The primary reference "System.Threading.Tasks.Dataflow, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the framework assembly "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "System.Threading.Tasks.Dataflow, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" or retarget your application to a framework version which contains "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".

如果我在这一点上尝试编译,我会出错,因为引用程序集中的类型和命名空间不可用,就好像根本没有引用程序集一样.

"添加引用"对话框没有任何 System.Runtime选项,但如果我手动选择C:\ Windows\Microsoft.NET\Framework\v4.0.30319 \并引用那里找到的System.Runtime程序集,则警告会消失我能够编译.

问题: …

reference target-framework visual-studio-2012

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

多线程网络刮刀?

我一直在考虑让我的web scraper多线程,而不是像普通的线程(例如,线程scrape =新的线程(函数);)但是像线程池这样的东西可以有很多线程.

我的刮刀通过使用for循环来刮擦页面.

for (int i = (int)pagesMin.Value; i <= (int)pagesMax.Value; i++)
Run Code Online (Sandbox Code Playgroud)

那么我怎么能用线程池这样的多线程函数(包含循环)多线程?我以前从未使用过线程池,我见过的例子对我来说很混乱或模糊.


我已经将我的循环修改为:

int min = (int)pagesMin.Value;
int max = (int)pagesMax.Value;
ParallelOptions pOptions = new ParallelOptions();
pOptions.MaxDegreeOfParallelism = Properties.Settings.Default.Threads;
Parallel.For(min, max, pOptions, i =>{
    //Scraping
});
Run Code Online (Sandbox Code Playgroud)

会有用还是我弄错了?

c# multithreading .net-4.0 scraper web

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