task

C#, Maximize Thread Concurrency

混江龙づ霸主 提交于 2020-01-24 20:37:20
问题 With the help of Google and community, I was able to build a nice set of methods allowing me to asynchronously call a function. This function is testing remote host properties, so it is idling most of the time. For this reason I would like to maximize the number of concurrent threads launched such that all calls can be processed in the minimum amount of time. Here is the Code I have so far: // Check remote host connectivity public static class CheckRemoteHost { // Private Class members

When will awaiting a method exit the program?

佐手、 提交于 2020-01-24 17:55:31
问题 I've been reading the following post, specifically this point: On your application’s entry point method, e.g. Main. When you await an instance that’s not yet completed, execution returns to the caller of the method. In the case of Main, this would return out of Main, effectively ending the program. I've been trying to do that, but I can't seem to make it exit. Here's the code I have: class Program { // ending main!!! static async Task Main(string[] args) { Task<Task<string>> t = new Task<Task

OpenMP - How does the thread decide when to defer a task and when to execute immediately

别等时光非礼了梦想. 提交于 2020-01-24 15:37:26
问题 The OpenMP specification document says that "When a thread encounters a task construct, it may choose to execute the task immediately or defer its execution until a later time". However, the specification does not say how this choice is made. How does the thread decide when to execute the task immediately and when to defer the execution? If this is implementation specific, how does compilers like gcc solve this? 回答1: There are two conditions coming from the standard: When an if clause is

Android - Background activity bring itself to foreground

大憨熊 提交于 2020-01-23 13:26:04
问题 I have the following situation: Activity A starts activity B User presses Home button & starts another app After a while, I want activity B to bring itself (not create new instance) to foreground How can I do this? I tried using intents with FLAG_ACTIVITY_REORDER_TO_FRONT, FLAG_FROM_BACKGROUND and set B's launch mode as singleTask, singleInstance but none of them work. 回答1: Just use this method in your activity as per your situation. it will work. protected void moveToFront() { if (Build

TaskCanceledException when not awaiting

允我心安 提交于 2020-01-23 13:03:31
问题 I seem to be getting a TaskCanceledException whenever I return another Task synchronously instead of awaiting it, following the guidelines in When at last you await. TaskCanceledException code public static class Download { public static Task<byte[]> FromYouTubeAsync(string videoUri) { using (var client = new HttpClient()) { return FromYouTubeAsync( () => client .GetStringAsync(videoUri), uri => client .GetByteArrayAsync(uri)); } } public async static Task<byte[]> FromYouTubeAsync( Func<Task

How can I monitor the Task queues in the .NET TaskSchedulers (across AppDomain)

十年热恋 提交于 2020-01-23 01:22:06
问题 As a developer, I would like to monitor the size (and progress) of work in the Task Queues in the TaskSchedulers so that I can evaluate whether an experienced slowdown under production load is due to the magnitude or perhaps stall of tasks scheduled. Normally I would simply attach the debugger and inspect task sizes, but: The application is running under mono and in production, so I cannot attach to it using visual studio I would like to deliver output of analysis on this data as surveillance

List Index Out of Range exception when creating a task

╄→尐↘猪︶ㄣ 提交于 2020-01-21 10:44:27
问题 The exact error: Index was out of range. Must be non-negative and less than the size of the collection. I've index arrays and lists countless times. I've used for loops with arrays and lists countless times. The data is there, it works. Except when I try to create a task for my function. Mind you, I successfully did this with a foreach loop for a similar function; this new one requires two arguments though, so I can't use a foreach loop properly. At least I don't think I can. Here is the

grunt: how to replace paths in html file using grunt task

梦想的初衷 提交于 2020-01-19 23:30:49
问题 inside my grunt configuration if have a variable which defines a directory which contains a css file. Now I would like to configure a grunt task which insert the value of this variable into a html file. For example, I can imagine that I have an index.html file as follows <!doctype html> <head> <link rel="stylesheet" href="<% pathToCss %>/styles.css"> ... But I cannot find a task which can do that for me. Any suggestions which grunt taks can do this for me ? 回答1: I just found out that it can

Why is Task<T> not co-variant?

≡放荡痞女 提交于 2020-01-18 16:05:41
问题 class ResultBase {} class Result : ResultBase {} Task<ResultBase> GetResult() { return Task.FromResult(new Result()); } The compiler tells me that it cannot implicitly convert Task<Result> to Task<ResultBase> . Can someone explain why this is? I would have expected co-variance to enable me to write the code in this way. 回答1: According to someone who may be in the know... The justification is that the advantage of covariance is outweighed by the disadvantage of clutter (i.e. everyone would

Why is Task<T> not co-variant?

帅比萌擦擦* 提交于 2020-01-18 15:59:30
问题 class ResultBase {} class Result : ResultBase {} Task<ResultBase> GetResult() { return Task.FromResult(new Result()); } The compiler tells me that it cannot implicitly convert Task<Result> to Task<ResultBase> . Can someone explain why this is? I would have expected co-variance to enable me to write the code in this way. 回答1: According to someone who may be in the know... The justification is that the advantage of covariance is outweighed by the disadvantage of clutter (i.e. everyone would