task

Task.WaitAll freezes app C#

穿精又带淫゛_ 提交于 2019-12-30 10:25:12
问题 I wanted to try out Threading.Task (C#) to run some work in parallel. In this simple example I have a form with progress bar and button. On click the RunParallel function is called. Without Task.WaitAll() it seems to run through fine. However, with the WaitAll statement the form shows and nothing happens. I dont understand what I am doing wrong in the setup below. Thanks in advance. public partial class MainWindow : Form { public delegate void BarDelegate(); public MainWindow() {

Calling Task.wait may not wait if the task has not yet started?

白昼怎懂夜的黑 提交于 2019-12-30 06:57:09
问题 I was reading Jeffrey Richter's clr via c# book and felt uncomfortable reading that task wait may not always wait and I quote "When a thread calls the Wait method, the system checks if the Task that the thread is waiting for has started executing. If it has, then the thread calling Wait will block until the Task has completed running. But if the Task has not started executing yet, then the system may (depending on the TaskScheduler ) execute the Task by using the thread that called Wait . If

C#/.NET 4.5 - Why does “await Task.WhenAny” never return when provided with a Task.Delay in a WPF application's UI thread?

回眸只為那壹抹淺笑 提交于 2019-12-30 06:42:12
问题 Given the following code, why does Task.WhenAny never return when provided with a Task.Delay of 1 second? Technically I'm not sure if it does return after a extended amount of time, but it doesn't after 15 seconds or so after which I manually kill the process. According to the documentation I shouldn't be required to manually start the delayTask, and in fact I receive a exception if I try to do so manually. The code is being called from the UI thread when a user selects a context menu item in

What does “long-running tasks” mean?

元气小坏坏 提交于 2019-12-30 02:42:31
问题 By default, the CLR runs tasks on pooled threads, which is ideal for short-running compute-bound work. For longer-running and blocking operations, you can prevent use of a pooled thread as follows: Task task = Task.Factory.StartNew (() => ..., TaskCreationOptions.LongRunning); I am reading topic about thread and task . Can you explain to me what are "long[er]-running" and "short-running" tasks? 回答1: In general thread pooling , you distinguish short-running and long-running threads based on

gulp watch doesn't watch

你离开我真会死。 提交于 2019-12-29 08:19:40
问题 Following is my gulpfile.js. There are a couple of more tasks in it and all are working fine - but the last task, watch doesn't. I've tried every possible combination of paths and files and what so ever, but still I don't have luck. I've read many answers on this here, but couldn't solve my problem. I tried to run gulp.watch with and without requiring gulp-watch, tried several different approaches on how to set up the task and so on and so on... var gulp = require('gulp'); var browserify =

Using tasks/ ThreadPool on IIS application (asp .net)

孤者浪人 提交于 2019-12-29 07:21:42
问题 We have an asp.net application on an iis 7. we need to create an async process to do calculating (using a web service) and not keeping the client waiting, we used ThreadPool to do that (i prefer Tasks but i am a server side guy). My questions are : 1. if using a thread pool on iis does it take threads from the iis pool from clients or from the OS ? 2. What would you use Tasks or ThreadPool (Tasks give you much more i know but the UI guys like the pool). Tanks 回答1: The ASP.NET host provides a

Using tasks/ ThreadPool on IIS application (asp .net)

爱⌒轻易说出口 提交于 2019-12-29 07:21:21
问题 We have an asp.net application on an iis 7. we need to create an async process to do calculating (using a web service) and not keeping the client waiting, we used ThreadPool to do that (i prefer Tasks but i am a server side guy). My questions are : 1. if using a thread pool on iis does it take threads from the iis pool from clients or from the OS ? 2. What would you use Tasks or ThreadPool (Tasks give you much more i know but the UI guys like the pool). Tanks 回答1: The ASP.NET host provides a

Cancel blocking AcceptTcpClient call

筅森魡賤 提交于 2019-12-28 13:46:32
问题 As everyone may already know, the simplest way to accept incoming TCP connections in C# is by looping over TcpListener.AcceptTcpClient(). Additionally this way will block code execution until a connection is obtained. This is extremely limiting to a GUI, so I want to listen for connections in either a seperate thread or task. I have been told, that threads have several disadvantages, however nobody explained me what these are. So instead of using threads, I used tasks. This works great,

Task unhandled exceptions

…衆ロ難τιáo~ 提交于 2019-12-28 13:33:10
问题 I'm trying to understand what is going on with exceptions that are thrown within a task object and never handled. On MSDN it said that: If you do not wait on a task that propagates an exception, or access its Exception property, the exception is escalated according to the .NET exception policy when the task is garbage-collected. So I don't quite understand in what way those exceptions affect program flow. I thought that those exceptions should interrupt execution as soon as they are garbage

How to handle Task.Run Exception

旧时模样 提交于 2019-12-28 12:15:30
问题 I had a problem with catching my exception from Task.Run I changed my code and my problem solved. I'm willing to figure out what is the difference between handling exceptions inside Task.Run in these two ways : In Outside function I can't catch the exception but in Inside I can catch it. void Outside() { try { Task.Run(() => { int z = 0; int x = 1 / z; }); } catch (Exception exception) { MessageBox.Show("Outside : " + exception.Message); } } void Inside() { Task.Run(() => { try { int z = 0;