English 中文(简体)
PLINQ执行长期任务
原标题:Cancelling long-running tasks in PLINQ

我正试图利用4.0网并行任务图书馆处理多种商品交易所的询问。 如果问题需要太多时间,我想取消,继续处理其余问题。

当有人问询超过门槛值时,该代码就停止了。 我认为我这样说,整个过程而不是单一交易都达到了取消的任务和时限。 如果我确定时间非常小(300米),那么它就要求进行所有搜索。

我认为我没有明显的东西。 事先感谢任何见解。

此外,这似乎还未停止漫长的执行。 这样做是否正确,一旦触发了长时间的争 que?

经修改的法典:

CancellationTokenSource cts = new CancellationTokenSource();
CancellationToken token = cts.Token;

var query = searchString.Values.Select(c =>myLongQuery(c)).AsParallel().AsOrdered()
                                        .Skip(counter * numToProcess).Take(numToProcess).WithCancellation(cts.Token);

  new Thread(() =>
  {
     Thread.Sleep(5000);
     cts.Cancel();
  }).Start();

  try
  {
     List<List<Threads>> results = query.ToList();
     foreach (List<Threads> threads in results)
     {
           // does something with data
     }
  } catch (OperationCanceledException) {
     Console.WriteLine("query took too long");
  }   
问题回答

PLINQ将污染在一系列因素之后的取消。 如果检查频率不足以满足您的要求,则确保全国扫盲和扫盲中心的所有昂贵代表定期打电话。

详情见本条款:Link

这只是一种猜测:问问问问(如通常的LINQ)是什么问题,因此直到以后才会处决?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签