How to start a continuation asynch without the original Task [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I'm a contractor, I've taken over a bunch of projects written by a developer who has left. One of the ASPX pages is using Tasks with a long chain of continuations to launch long processing.
When I set breakpoints in a continuation they are never hit unless I call Wait() on the Task, so I assume the Task is never being executed. I can't call Start() on a continuation and I have no access to the creation of the original Task because it occurs in a 3rd party library. How can I start the Task asynchronously?

A continuation Task starts only after the antecedent Task completes (that is the whole point of continuation). And there is no alternative way to start it, assuming you can't modify the code that creates the continuation.

Related

Dangers of not using await [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
To enhance performance, I want to exit a function without waiting for all async functions to complete. I only care about the results of the first function. The others should complete when ever and log their own exceptions.
// I care about this result
int? bookingId = await BookingService.SaveBooking(...);
// These should run async in the background. All async methods.
EmailService.SendEmail(...);
CreditCardService.SaveCard(...);
SMSService.SendSms(...);
return bookingId;
What are the risks of omitting await keyword there?
The main risk here is that they fail and cause unobserved exceptions. A secondary risk is that they attempt to interact with some async state that no longer makes sense once the main operation has completed. If you're happy that neither of these things are a problem, you should be fine - but you should be a little cautious with this approach. This is essentially a "fire and forget" scenario - the compiler will try to fight you

Real world explanation of using ConfigureAwait to false in c# [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I am learning async/await and I came across the blog in which it's mentioned about using ConfigureAwait with async/await. It read's like this:
ConfigureAwait accepts a Boolean continueOnCapturedContext parameter: passing true means to use the default behavior, and passing false means that the system doesn’t need to forcefully marshal the delegate’s invocation back to the original context and can instead execute the delegate wherever the system sees fit.
The information does not tell much in detail, can anybody explain the real world example of using it. I also searched further and found out that it should be used with HTTP calls and such, but didn't got concrete answer for why should we use it.
Reference link: https://blogs.msdn.microsoft.com/windowsappdev/2012/04/24/diving-deep-with-winrt-and-await/
This is useful for scenarios where a single thread handles multiple actions, think Dispatcher thread in WPF or the host thread in IIS.
It is most obvious in Asp.Net (on Windows and full .net, hosted in IIS) -> if you do not specify .ConfigureAwait(false) and the request takes a significant amount of time, no other requests can be processed by the same w3wp.exe process.
The whole app is essentially blocked.
What this is doing is saying that the control can return to this stack using another thread from the threadpool, essentially unblocking the main thread.

How to safely close a main form when there are child threads opening message boxes [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
In my C# code there is a Main window which starts multiple threads.Some of these thread cause message boxes to show.When i close the main window I need all the threads i started to be aborted safely.I tried doing it by adding the threads to a list and then aborting them.But everytime ThreadAbort exception is thrown.
Please suggest me a way to do this
The very purpose of Thread.Abort is raising a ThreadAbortException. This kills the thread.
From MSDN:
Thread.Abort Method
Raises a ThreadAbortException in the thread on which it is invoked, to begin the process of terminating the thread. Calling this method usually terminates the thread.
Using Thread.Abort will not terminate the thread in a clean way. The usual safe solution for stopping a thread is creating a volatile bool stop flag on that thread, which your thread checks from time to time to know whether it should stop.

way of writing for dotnet 3.5 quick and dirty async method [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
In my C# code I am calling some tracking services by using (apparently) inefficient 3rd party libraries.
the problem is that they are blocking my thread and the user get some lags.
I want to wrap all the calling to this 3rd parties in an async method.
What is the best and easiest way to achieve it?
I don't need any response from this call, I just want to remove it from the main thread..
Is there a quick and dirty solution?
Maybe something like setTimeOut(function(){/*code here*/},1) in JavaScript?
I am searching for a solution for some time, but dot net 3.5 not supporting the simple and fast async approaches.
There are many ways in .NET to write multithreaded code. Jon Skeet covered some of them in this blog post: http://www.yoda.arachsys.com/csharp/threads/
So the idea here is to spawn a new thread (or use a thread from the thread pool) to execute the slow code inside. This way the main thread won't be blocked.

Will a single task in C# be executed in parallel on a multi-core system? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I am just finding my way around parallel programming in C# and understood the significance of cores and true parallel programming.
But I still have a question:
Say I have a long running task does that mean this will be executed using threads from thread pool and in different cores for true parallel programming.
Or does it depend on the actual delegate that is passed onto the task?
I Hope my question is clear.
The delegate itself makes no difference. It is the TaskScheduler that matters.
The default TaskScheduler will run them via the ThreadPool.. to have them run synchronously, you would pass in a TaskScheduler instance that is currently being used.. such as the static TaskScheduler.FromCurrentSynchronizationContext.
True parallel programming requires multiple cores since threads must execute on separate threads to truly run in parallel.. In a single core system you can only achieve fake parallelism since different treads must share the core through allocated time slots. Other treads are waiting while the current thread is running on the single core.

Categories