task

C++ bound method queue (task manager/scheduler?)

大兔子大兔子 提交于 2019-12-07 22:46:38
问题 Is there a method/pattern/library to do something like that (in pseudo-code): task_queue.push_back(ObjectType object1, method1); task_queue.push_back(OtherObjectType object2, method2); so that I could do the something like: for(int i=0; i<task_queue.size(); i++) { task_queue[i].object -> method(); } so that it would call: obj1.method1(); obj2.method2(); Or is that an impossible dream? And if there's a way to add a number of parameters to call - that would be the best. Doug T. please see this

Have multiple calls wait on the same internal async task

让人想犯罪 __ 提交于 2019-12-07 22:34:23
问题 (Note: this is an over-simplified scenario to demonstrate my coding issue.) I have the following class interface: public class CustomerService { Task<IEnumerable<Customer>> FindCustomersInArea(String areaName); Task<Customer> GetCustomerByName(String name); : } This is the client-side of a RESTful API which loads a list of Customer objects from the server then exposes methods that allows client code to consume and work against that list. Both of these methods work against the internal list of

How to properly parallelize worker tasks?

雨燕双飞 提交于 2019-12-07 22:15:21
问题 Consider the following code snippet and notice the difference in total runtime between setting numberTasksToSpinOff equal to 1 and then 3,4, or more (depending on thread resources on your machine). I notice much longer run times when spinning off more tasks. I passed on purpose a data collection into each worker instance that each worker tasks reads from at the same time. I thought that tasks can access a shared data structure without blocking as long as those operations are only reads or

Equivalent Task in .NET 2.0 [duplicate]

落爺英雄遲暮 提交于 2019-12-07 21:54:40
问题 This question already has an answer here : Is it possible to use the Task Parallel Library (TPL) in C# 2.0? (1 answer) Closed 4 years ago . I know .NET 2.0 it's probably really old now. But I have the code that I want to compile under .NET 2.0. Unfortunately, the source uses .NET 4.0 System.Threading.Tasks Here the code: int count = GetCount(); Task[] tasks = new Task[count]; for (int p = 0; p < count; p++) { int current = p; tasks[p] = Task.Run(() => { // Do something here }); } Task.WaitAll

WinForms TPL Pattern w/ Multiple Tasks & UI Sync - is this correct?

微笑、不失礼 提交于 2019-12-07 18:32:49
问题 I'm new to the TPL (Task-Parallel Library) and am wondering if the following is the most efficient way to spin up 1 or more tasks, collate the results, and display them in a datagrid. Search1 & Search2 talk to two separate databases, but return the same results. I disable the buttons and turn on a spinner. I'm firing the tasks off using a single ContinueWhenAll method call. I've added the scheduler to the ContinueWhenAll call to update form buttons, datagrid, and turn off the spinner. Q: Am I

What's the best way to wrap a synchronous code as an async Task?

半世苍凉 提交于 2019-12-07 17:55:20
问题 I am implementing an interface method that is asynchronous (returns Task). However, my implementation is by necessity synchronous. What's the best way to do this? Is there some built-in way to do this? Here are several options I'm considering: Option 1: Task.FromResult return Task.FromResult(ComputeResult()); This is good because my code runs synchronously. The disadvantage is that if ComputeResult() fails or is canceled my method throws instead of returning a failed task. Option 2: Task.Run

What is the right way to define versionName as ext variable in Android build.gradle?

流过昼夜 提交于 2019-12-07 17:53:57
问题 I tried to define versionName as an ext variable to be used in my gradle configuration file app/build.gradle. ext { versionCode = 19 versionName = "1.2.3" ... } ... android { ... defaultConfig { ... versionCode versionCode versionName versionName } ... } ... task updateReleaseMetadata(type:Exec) { commandLine 'sh' args "MyShellScript.sh", versionName } ... It seemed work fine. However my android code failed to retrieve the versionName as following PackageInfo pi = context.getPackageManager()

Deadlock while blocking async HttpClient call within a task continuation

若如初见. 提交于 2019-12-07 14:07:11
问题 I am trying to wrap my head around synchronously calling async functions and deadlock. In the below example I am blocking an async call which internally uses ConfigureAwait(false) which as far as I can tell should prevent deadlock. The first call to the web service does not deadlock. However, the second one that happens within a continuation that syncs back to the UI thread deadlocks. GetBlocking_Click is a click event in a WPF app so both the first and the second request happen on the UI

UnobservedTaskException - Where did the task come from

若如初见. 提交于 2019-12-07 13:34:42
问题 In my MVC application, I sometimes get an exception like: System.Net.WebException: The request was aborted: The request was canceled. at System.Net.HttpWebRequest.BeginGetRequestStream(AsyncCallback callback, Object state) at System.Net.Http.HttpClientHandler.StartGettingRequestStream(RequestState state) at System.Net.Http.HttpClientHandler.<>c__DisplayClass4.<PrepareAndStartContentUpload>b__0(Task task) at System.Threading.Tasks.Task.Execute() --- End of inner exception stack trace --- EDIT

Why Google App Engine Tasks can spuriously be executed more than once?

会有一股神秘感。 提交于 2019-12-07 12:57:34
问题 Why Google App Engine Tasks can be executed more than once? According do Brett Slatkin talk from Google I/O 2009, it is possible for a task to spuriously run twice even without server failures! This has something to do with spurious wakeup of threads? 回答1: Brant Slatkin gave a similar talk at I/0 2010. I don't know that he ever gave details of how or when this could happen. His point was that because of the way Task Queues work it is possible by design for tasks to be reenqueued. Because of