task

Wrap a synchronous function in Asynchronous call c#

自闭症网瘾萝莉.ら 提交于 2019-12-23 05:25:54
问题 I have a server, which must poll an equipment through the network, to obtain information, process it and then send it to the users. The equipment survey becomes a synchronous blocking function. My question is: How to create an own asynchronous function version to perform this function using Task or another asynchronous pattern??? Consider the following code to get information from equipment: IEnumerable<Logs> GetDataFromEquipment(string ipAddress) { Equipment equipment = new Equipment(); /

Threading Task not executing in IIS

只谈情不闲聊 提交于 2019-12-23 02:42:15
问题 I have a .Net application that uses Forms Authentication mode and has a function that calls an asynchronous task. Below is the snippet of the task: Task.Factory.StartNew(() => { UploadFunction(); }, tokenSource.Token, TaskCreationOptions.LongRunning,TaskScheduler.Default); The thread is working fine when I test in on the Visual Studio IDE. The issue is when I deploy it, the threading task seems to be skipped or not executed by the system. I've read an article that this can be caused by

How to yield/resume OpenMP untied tasks correctly?

佐手、 提交于 2019-12-22 18:37:50
问题 I wrote a small C program to assess OpenMP's capability to yield to another task when idle time in a task occurs (e.g. wait for communicated data): #include <stdio.h> #include <sys/time.h> #include <omp.h> #define NTASKS 10 double wallClockTime(void) { struct timeval t; gettimeofday(&t, NULL); return (double)(t.tv_sec + t.tv_usec/1000000.); } void printStatus(char *status, int taskNum, int threadNum) { #pragma omp critical(printStatus) { int i; for (i = 0; i < taskNum; i++) printf(" ");

Why does Type.IsGenericType return TRUE for Task without return type obtained by reflection from method but typeof(Task).IsGenericTyp returns FALSE

China☆狼群 提交于 2019-12-22 17:37:32
问题 Can someone explain this? Per documentation IsGenericType indicatesing whether the current Type represents a type parameter in the definition of a generic type or method. So this (LINQPad) code: bool bStraight = typeof(Task).IsGenericType; bStraight.Dump("typeof(Task).IsGenericType"); works as expected and yields the output: typeof(Task).IsGenericType False But when I retrieve it from a method by reflection: public class MyClass { public async Task Method() { await Task.Run(() => { Thread

Why can't see all task when use 'tasks' task in Gradle?

大兔子大兔子 提交于 2019-12-22 12:39:11
问题 task startSession << { chant() } def chant() { ant.echo(message: 'Repeat after me...') } 3.times { task "yayGradle$it" << { println 'Gradle rocks' } } yayGradle0.dependsOn startSession yayGradle2.dependsOn yayGradle1, yayGradle0 task groupTherapy(dependsOn: yayGradle2) In my script I have startSession task, groupTherapy task and three dynamically generated tasks yayGradle0-3. When I am executing: gradle tasks Part of the output is: Other tasks ----------- groupTherapy Where are the other

concat result of three tasks in an async method in a proper way

北慕城南 提交于 2019-12-22 11:19:36
问题 I am very new in async programming. I was wonder if there is any way for these tasks to run simultaneously. Consider I have this code: public async Task<IList<WebData>> GetAllAsync() { var twitterData = await ProvidetwitterDataAsync(); var facebookData = await ProvidefacebookDataAsync(); var linkedinData = await ProvidelinkedinDataAsync(); return twitterData .Concat(facebookData ).Concat(linkedinData ).ToList(); } I think because I used await twitterData that Task should be done and after

Application.DoEvents vs await Task.Delay in a loop

為{幸葍}努か 提交于 2019-12-22 10:56:40
问题 Much to my discontent, I need to use a WebBrowser control in one of my apps. One of the things I also need to do is wait for an element to become visible/class changes/etc, which happens well after the DocumentCompleted event is fired, making the event close to useless in my case. So currently I have something like... while (webBrowser.Document?.GetElementById("id")?.GetAttribute("classname") != "class") { Application.DoEvents(); Thread.Sleep(1); } Now I've read in multiple places that

How do I overwrite a task in gradle kotlin-dsl

梦想与她 提交于 2019-12-22 10:28:08
问题 In Groovy, I overwrite a task like this: task jar(overwrite: true) { ... } How do I do that with Kotlin-dsl? I know that I can create a task like this: tasks { val jar by creating { ... } } but I can't find the equivalent way to declare it as overwrite, this leads to an error 回答1: By opening an issue on the kotlin-dsl github I found the correct syntax: tasks.replace("jar") { ... } However, this is the old way and does not work within a tasks { } block, so this issue will be further tracked

Convert synchronous zip operation to async

天大地大妈咪最大 提交于 2019-12-22 10:17:38
问题 We got an existing library where some of the methods needs to be converted to async methods. However I'm not sure how to do it with the following method (errorhandling has been removed). The purpose of the method is to zip a file and save it to disk. (Note that the zip class doesn't expose any async methods.) public static bool ZipAndSaveFile(string fileToPack, string archiveName, string outputDirectory) { var archiveNameAndPath = Path.Combine(outputDirectory, archiveName); using (var zip =

How to throttle script that creates celery tasks faster than they're consumed?

喜欢而已 提交于 2019-12-22 09:41:15
问题 I have a script that generates millions of Celery tasks, one per row in the DB. Is there a way to throttle it so that it doesn't completely flood Celery? Ideally I want to keep Celery busy, but I don't want the length of the Celery queue to exceed a few dozen tasks since that's just a waste of memory (especially since without some kind of throttle the script will add millions of tasks to the queue almost instantly). 回答1: I've spent some time on this problem over the past several days and came