task

C# cancel a long running task that not a loop

↘锁芯ラ 提交于 2020-01-03 18:59:08
问题 I am new to c# task, what I want to do is convert downloadThread = new Thread(DownLoadFile); downloadThread.Start(); to task like var t = Task.Factory.StartNew(DownLoadFile); I also knew use CancellationTokenSource to cancel. But examples I saw are all long loop running thread, like for, foreach, while, and check IsCancellationRequested to cancel a task in loop. if (ct.IsCancellationRequested) { break; } but my long running task is to download a file from ftp, GetFile is from third party dll.

Problems with scheduling tasks from a UI .continuewith task

吃可爱长大的小学妹 提交于 2020-01-03 17:09:50
问题 My application schedules a long running task using the following code: Task.Factory.StartNew<bool>((a) => WorkTask1(), TaskCreationOptions.LongRunning | TaskCreationOptions.AttachedToParent) .ContinueWith(antecedent => WorkCompletedTask1(antecedent.Result), TaskScheduler.FromCurrentSynchronizationContext()); WorkCompletedTask1 is scheduled and displays results on the UI as expected. Depending on results from WorkTask1, WorkCompletedTask1 may schedule additional tasks using the following

Async Method throws Exception

南楼画角 提交于 2020-01-03 07:11:12
问题 I'm currently having some problems with a method that throws an exception but I'm not sure why. The exception makes my application crash. System.NullReferenceException: Object reference not set to an instance of an object. at Myapp.AutoProcess.<ToRead>d__36.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__1(Object state) at System.Threading.QueueUserWorkItemCallback.WaitCallback

Excel Interop: Creating instance with Task.Run results in exception System.EntryPointNotFoundException

送分小仙女□ 提交于 2020-01-02 08:31:26
问题 Here is my minimal example producing the problem: using System.Runtime.InteropServices; using System.Threading.Tasks; using Excel = Microsoft.Office.Interop.Excel; class Program { static void Main(string[] args) { Task.Run(() => { Excel.Application app = new Excel.Application(); if (app != null) { app.Quit(); Marshal.FinalReleaseComObject(app); app = null; } }); } } This results in the following exception: The last part in Japanese says the "EventSetInformation" of DLL advapi32.dll entry

Task.ContinueWith not working how I expected

寵の児 提交于 2020-01-02 04:49:27
问题 Consider the following code. I am starting with a task that does nothing, and then using ContinueWith() to start 10 calls to a method that increments a counter. When I run this program, it prints "0", indicating that the increment() method hasn't been called at all. I was expecting it to be called 10 times, since that's how many times I called ContinueWith(). If I uncomment the "Thread.Sleep(20)" line, then it prints "10" as expected. This happens in either release or debug mode. My system is

AppDomain await async Task prevent SerializationException

放肆的年华 提交于 2020-01-02 04:39:07
问题 I have a windows service, which loads assembly in another AppDomain at runtime. Then it executes them and finally unloads the AppDomain. The problem is the execute method from the plugins are async tasks and I get the SerializationException because Task does not inherit from MarshalByRefObject. I wrapped the plugin in a proxy which inherits from MarshalByRefObject, but I dont know how to get rid of the SerializationException? public interface IPlugin : IDisposable { Guid GUID { get; } string

Recurring tasks in ASP .NET

纵饮孤独 提交于 2020-01-01 11:48:12
问题 I have an ASP .NET website running on GoDaddy in a shared environment. The application is a subscription-based service with options for recurring billing to users. Every hour, we need to synchronize user data with our payment processor to update users who have upgraded or cancelled their accounts. The payment processor, does not have a mechanism for calling a URL or otherwise notifying us of changes. The problem: We need to create a background thread that runs some code at a predefined

Can you call Wait() on a task multiple times?

旧街凉风 提交于 2020-01-01 11:02:47
问题 I want to run initializations of some objects asynchronously, but some objects depend on others being initialized. And then all objects need to be initialized before the rest of my application continues. Is it possible to call Wait() on a task and later call Wait() on it again, or as in my example WaitAll() on a collection where it is included? Dictionary<String, Task> taskdict = new Dictionary<String, Task>( ); taskdict.Add( "Task1", Task.Factory.StartNew( ( ) => { //Do stuff } ) ); taskdict

Update github markdown Tasklists ( GFM ) via commit

别说谁变了你拦得住时间么 提交于 2020-01-01 09:36:08
问题 As you know you can create a tasklist in GFM (github flavoured markdown) by using the tags - [ ] for unchecked task - [x] for a checked task I was wondering if it is somehow possible to check a task in a given issue's tasklist by commeinting it in a commit. 回答1: Well the simple answer is NO, you cannot tick task list by adding comments to a commit message. But what you can actually do, along with a commit you can update the .markdown that contains this list. 来源: https://stackoverflow.com

Checking status of Task Queue in Google App Engine

試著忘記壹切 提交于 2020-01-01 04:46:04
问题 I'm putting several tasks into a task queue and would like to know when the specific tasks are done. I haven't found anything in the API about call backs, or checking the status of a task, so I thought I'd see what other people do, or if there's a work around (or official) way to check. I don't care about individual tasks, if it helps, I'm putting 6 different tasks in, and want to know when all 6 are complete. Thanks! 回答1: The new REST/JSON task queue API will let you do this. http://code