task

Cannot implicitly convert type 'int' to '…Tasks<int>'

亡梦爱人 提交于 2019-12-21 12:18:19
问题 if this is async, it'll return with no error, why is it throwing an error without being async, async is worthless in this operation. public Task<int> countUp() { string compare = txtTag.Text; int count = 0; for (int i = 0; i < dataGridView1.Rows.Count; i++) { if (compare == dataGridView1[0, i].Value.ToString()) { BeginInvoke(new Action(() => { count++; txtCount.Text = count.ToString(); })); } } return count; } 回答1: Well, you could return a completed Task: return Task.FromResult(count); http:/

tornado常见的异步非堵塞写法

倾然丶 夕夏残阳落幕 提交于 2019-12-21 10:52:54
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 非堵塞和异步有什么区别? 非堵塞 在tornado的框架中非堵塞一般指得是网络I/O层面的socket数据接收模式(select或者epoll),不论用哪个模式,最终程序都会收到数据并处理数据(这个数据要么被转发、要么被解析和处理)。 非堵塞的弊端: 如果处理一个密集计算的请求需要花费10秒钟(就是堵塞了10秒钟),当两个或多个请求同时到达时,只要第一个被接受处理没结束,其他全部请求都要等,并且挨个挨个等到被轮询结束。这就是单线程事件还回机制(非堵塞机制), 对堵塞零容忍, 任何一个地方堵住了还回线程,其他全部请求都被堵住。 也就是说采用了非堵塞模式之后,最好不要用堵塞(常规解析数据的函数)的代码块来解析数据。 异步 异步的作用是将堵塞代码错开来,不放在当前接受数据的线程中处理, 要么丢到rabbitmq/zeromq/activemq中交给另外一个进程去处理,要么用其他线程或进程来处理。 让监听数据的这个socket收到数据后直接抛给其他程序来处理,然后立马保持监听状态,这样子程序的循环能力就非常强。 再就是要提的一点,tornado本身的ioloop就采用epool/select/kqueue来完成非堵塞动作,咱们使用tornado只要把异步的代码写好就可以很好的发挥出tornado的优势了。

Pass an argument to task in C++/CLI?

耗尽温柔 提交于 2019-12-21 07:49:26
问题 I have this code for the C# in Visual Studio 2012. public Task SwitchLaserAsync(bool on) { return Task.Run(new Action(() => SwitchLaser(on))); } This will execute SwitchLaser method (public nonstatic member of a class MyClass ) as a task with argument bool on. I would like to do something similar in managed C++/CLI. But I am not able to find out any way how to run a task, which will execute a member method taking one parameter. Current solution is like this: Task^ MyClass::SwitchLaserAsync(

How many tasks are too many?

拥有回忆 提交于 2019-12-21 07:03:31
问题 I'm currently working on an application that relies on many different web services to get data. Since I want to modularize each service and have a bit of dependency in there (service1 must run before service 2 and 3 etc), I'm running each service in its own task. The tasks themselves are either running actively, meaning they're sending their request to the web service and are waiting for a response or processing the response waiting (via monitor and timeout) - once a task finishes all waiting

Using TPL Task from WCF

房东的猫 提交于 2019-12-21 05:36:13
问题 In order to optimize some server-side database calls I decided to use System.Threading.Tasks.Task to parallelize several database calls then use Task.WaitAll() to get all the results, package them up and send them to the client via WCF. This seems to work fine when testing on the dev web server in Visual Studio (cassini) but does not work when deployed to IIS. Profiling the client calls (with firebug) shows that calls get to IIS but no corresponding calls are submitted to SQL Server. Anyone

Producer-Consumer using OpenMP-Tasks

半腔热情 提交于 2019-12-21 05:02:32
问题 I'm trying to implement a parallel algorithm using tasks within OpenMP. The parallel programming pattern is based on the producer-consumer idea, but since the consumer process is slower than the producer, I want to use a few producers and several consumers. The main idea is to create as many OS threads as producers and then each of these will create tasks to be done in parallel (by the consumers). Every producer will be associated with a proportional number of consumers (i.e numCheckers

Timing out the execution time of a controller/method in Spring

送分小仙女□ 提交于 2019-12-21 03:58:22
问题 I have a Spring controller that is currently being accessed normally, but i want to change the implementation in such a way that if the task the controller is performing takes more than a defined time for instance 10 seconds then the controller can respond with a "your request is being processed message" to the caller, but if the method returns within time then the response is passed to the calling method from the controller, in other words i want timed asynchronous execution from a Spring

TPL Dataflow vs plain Semaphore

巧了我就是萌 提交于 2019-12-21 02:52:10
问题 I have a requirement to make a scalable process. The process has mainly I/O operations with some minor CPU operations (mainly deserializing strings). The process query the database for a list of urls, then fetches data from these urls, deserilize the downloaded data to objects, then persist some of the data into crm dynamics and also to another database. Afterwards I need to update the first database which urls were processed. Part of the requirement is to make the parallelism degree

Why does Autowiring not function in a thread?

江枫思渺然 提交于 2019-12-20 23:25:17
问题 I've made a maven project in Spring 3.0, I've made some DAO, services and controllers, in one of mine controller I call a service in which I start a thread, the problem is that in the thread I declare a "service variable" that should be initialized with Autowired annotiation, but it doesn't work and the variable isn't initilized and has the value null. this is the thread class package com.project.tasks; import org.springframework.beans.factory.annotation.Autowired; import org.springframework

what is the correct way to cancel multiple tasks in c#

和自甴很熟 提交于 2019-12-20 17:18:25
问题 I have a button thats spawns 4 tasks. The same button changes to a cancel button and clicking this should cancel all 4 tasks. Should I pass the same cancel token to all 4 tasks and have them poll on the same token for IsCancelRequested ? I am confused after reading the msdn doc on createlinkedtokensource. How is this normally done ? thank you Update: Task.WaitAll() waits tills all tasks complete execution . Similarly how to know when all tasks have been canceled once the shared cancel token