简体   繁体   English

在处理先前加载的数据时从数据库加载新行以进行缓冲

[英]Load new rows from database for buffering while processing previous loaded data

I'm trying to retrieve, process and send data from database to a web service. 我正在尝试检索,处理数据库中的数据并将其发送到Web服务。

Now I send data concurrently using Parallel.ForEach like this: 现在,我使用Parallel.ForEach同时发送数据,如下所示:

while (true)
{
    var ctrl = new DataController();
    var list = ctrl.GetData();

    if (list == null)
    {
        SaveLogFile("No record retrived", @"C:\log\try-sending-log-");
        continue;
    }
    Parallel.ForEach(list, SendToWebService);
}

How can i load and buffer new rows during Parallel.ForEach works on sending data? Parallel.ForEach发送数据期间如何加载和缓冲新行?

Parallel.ForEach will wait until all task will be executed. Parallel.ForEach将等待,直到所有任务都将执行。 if you want to start is async than wrap the Parallel.ForEach(list, SendToWebService); 如果要启动是异步的,则可以包装Parallel.ForEach(list, SendToWebService); in Task.Factory.StartNew but please take additionaly care of life circle of all tasks that will be triggered by the StartNew Task.Factory.StartNew但是请特别注意StartNew将触发的所有任务的生命周期

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM