taskfactory

Different exception handling between Task.Run and Task.Factory.StartNew

蓝咒 提交于 2020-01-22 10:53:57
问题 I encountered an issue when I was using Task.Factory.StartNew and tried to capture an exception that is thrown. In my application I have a long running task that I want to encapsulate in a Task.Factory.StartNew(.., TaskCreationOptions.LongRunning); However, the exception isn't caught when I'm using Task.Factory.StartNew . It is however working as I expect when I use Task.Run , which I thought was just a wrapper on Task.Factory.StartNew (according to for instance this MSDN article). A working

Different exception handling between Task.Run and Task.Factory.StartNew

筅森魡賤 提交于 2020-01-22 10:53:12
问题 I encountered an issue when I was using Task.Factory.StartNew and tried to capture an exception that is thrown. In my application I have a long running task that I want to encapsulate in a Task.Factory.StartNew(.., TaskCreationOptions.LongRunning); However, the exception isn't caught when I'm using Task.Factory.StartNew . It is however working as I expect when I use Task.Run , which I thought was just a wrapper on Task.Factory.StartNew (according to for instance this MSDN article). A working

GUI froze while Dispatcher.BeginInvoke or Task.StartNew

三世轮回 提交于 2019-12-24 10:13:18
问题 NOTE: Depends on this quetion Hi. I have a view-model like this: public class ViewModel { private readonly IPersonService _personService; private readonly ObservableCollection<SearchPersonModel> _foundedList; private readonly DispatcherTimer _timer; private readonly Dispatcher _dispatcher; private CancellationTokenSource _tokenSource; public SearchPatientViewModel(IPersonService personService) { _personService = personService; _foundedList = new ObservableCollection<SearchPersonModel>();

WPF FormattedText “The system cannot find the file specified” exception in a service

不打扰是莪最后的温柔 提交于 2019-12-22 18:29:11
问题 We are using the WPF FormattedText object to determine text size in a service that grabs the latest news headlines from an RSS feed. The text retrieved needs to be in a specified canvas size. The service runs the code every 10 seconds and uses up to 2 threads if one takes longer than that. I'm using TaskFactory (which I've overridden the LimitedConcurrencyLevelTaskScheduler to limit to the amount of threads I specified). This works great, except after several days (the length is variable), we

It takes more than a few seconds for a task to start running

馋奶兔 提交于 2019-12-11 17:42:41
问题 I'm developing an application using WPF and C# . I have the following code: var tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; Task task = Task.Factory.StartNew(() => { // Some action that returns a boolean - **CODE_A** }).ContinueWith((task2) => { result= task2.Result; if (!result) { //Another action **CODE_B** } }); }, token); Usually CODE_A starts running immediately, and after less than a second, CODE_B starts executing. But, sometimes it takes

System.Threading.ThreadAbortException fired in new thread

别等时光非礼了梦想. 提交于 2019-12-11 03:14:34
问题 I am currently working in .net c# 4.0 and have come across an issue with some code that I written that is causing me some headaches. I am using the System.Threading.Tasks.TaskFactory class in conjunction with System.Threading.Tasks.TaskScheduler to start a new thread in my console application where the function of the thread is to check if an item has been added to a queue. When an item is added to the queue, it processes it. So the queue contains emails to be sent and once an email is added

Run multiply instances of the same method simultaneously in c# without data loss?

与世无争的帅哥 提交于 2019-12-08 06:46:21
问题 I really don't understand Tasks and Threads well. I have a method inside three levels of nested for that I want to run multiple times in different threads/tasks, but the variables I pass to the method go crazy, let me explain with some code: List<int> numbers=new List<int>(); for(int a=0;a<=70;a++) { for(int b=0;b<=6;b++) { for(int c=0;b<=10;c++) { Task.Factory.StartNew(()=>MyMethod(numbers,a,b,c)); } } } private static bool MyMethod(List<int> nums,int a,int b,int c) { //Really a lot of stuff

WPF FormattedText “The system cannot find the file specified” exception in a service

不想你离开。 提交于 2019-12-06 15:57:22
We are using the WPF FormattedText object to determine text size in a service that grabs the latest news headlines from an RSS feed. The text retrieved needs to be in a specified canvas size. The service runs the code every 10 seconds and uses up to 2 threads if one takes longer than that. I'm using TaskFactory (which I've overridden the LimitedConcurrencyLevelTaskScheduler to limit to the amount of threads I specified). This works great, except after several days (the length is variable), we start to get the following exceptions. The same code was working fine before we started using TPL to

Different exception handling between Task.Run and Task.Factory.StartNew

不想你离开。 提交于 2019-12-03 05:47:00
I encountered an issue when I was using Task.Factory.StartNew and tried to capture an exception that is thrown. In my application I have a long running task that I want to encapsulate in a Task.Factory.StartNew(.., TaskCreationOptions.LongRunning); However, the exception isn't caught when I'm using Task.Factory.StartNew . It is however working as I expect when I use Task.Run , which I thought was just a wrapper on Task.Factory.StartNew (according to for instance this MSDN article ). A working example is provided here, the difference being that the exception is written to console when using

Create a Task with an Action<T, T, … n> multiple parameters

為{幸葍}努か 提交于 2019-12-01 14:47:04
I want to add multiple parameter in a Task containing Action. I reviewed the existing stack-overflow question Create a Task with an Action<T> Kindly assist me how to pass multiple arguments in a Action method in a Task Action<string, int> action = (string msg, int count) => { Task.Factory.StartNew(async () => { await LoadAsync(msg, count); }); }; Task task = new Task(action, ....); The Action Method is public static async Task<string> LoadAsync(string message, int count) { await Task.Run(() => { Thread.Sleep(1500); }); Console.WriteLine("{0} {1} Exceuted Successfully !", message ?? string