multiple awaits and async methods in an application [closed] - c#

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 6 years ago.
Improve this question
I'm in the process of converting our data layer for a fairly large and complex WCF application to talk to the database asynchronously.
This has resulted in async and awaits being littered everywhere in the calling/consuming code.
Looking at the stack trace for a typical request I can already see many sections for the System.Runtime.CompilerServices.TaskAwaiter doing it's thing with await. And I have only just started this task!
I understand what .net does when it encounters async/await, so my question is the following: Is the extra overhead associated working with async/await worth it when the result is quite a few async methods from the beginning of a request to the end? I understand the benefits of calling the database asynchronously but is there a limit? Particularly when the calling application is fairly large and complex (or more appropriately a large and long call-stack).
Thanks.

Related

How to Process large JSON Data By MultiThreading 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 2 years ago.
Improve this question
I am new to threading and Multithreading . I have a method which Fetches Ids as input in JSON format from DB as
{
"ID": ["1",
....,
.....
"30000"]}
Now these Ids are to be processed again via WebAPI POST call. The issue is,though the code is optimized, it is taking hours to process all data.
How can I process these Ids in batch or multi threading to make it faster?
Recent versions of .NET have great libraries you can use that take care of the multi-threading for you.
Check out the Parallel For Each loop: https://learn.microsoft.com/en-us/dotnet/api/system.threading.tasks.parallel.foreach?view=netcore-3.1
You pass it a list and everything inside the loop is executed once for each item in the list and C# will do some of the iterations in parallel (multi-threaded). That means you could do your processing for more than one ID in parallel.
Whether or not it improves performance depends on the environment and work being done.

Thread State Management in Asynchronous Programming [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 6 years ago.
Improve this question
I am new to asynchronous programming in .Net using C#. All I have understood so far is :
With asynchronous programming, threads that are waiting for a web service or database to return data are freed up to service new requests until the data the is received.
Once the data is received, the thread is restarted and continue processing the code that comes after that call.
Now , I wanted to know in details How the state is managed for the thread so that it can start executing from the point the async call was made.
If it uses a stack to handle that, Can some one please give me an insight into the process?
Thanks,
Mayank
Now , I wanted to know in details How the state is managed for the thread so that it can start executing from the point the async call was made.
Async method are divided into smaller chunks. Basically, when compiling async method, for every await keyword new method is generated.
Keep in mind, that this is a big simplification and it's all done behind the scenes and you really don't need to know how it works in order to use it.

Synchronous method vs Thread.Sleep() [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 8 years ago.
Improve this question
I can't understand the difference between Thread.Sleep() and synchronous methods. Please explain..
Is synchronous method in C# is similar to Thread.Sleep()?.
No, other than Thread.Sleep is a synchronous method.
A synchronous method is one where the entirety of their functionality happens before returning control to the caller.
Thread.Sleep is a function which causes the executing thread to block for the specified number of milliseconds (not exactly, but close due to the CPU thread scheduler). It executes synchronously and wouldn't be as useful in an asynchronous method.
However, saying they are the same thing would be a misnomer, as there are plenty of synchronous methods that are not Thread.Sleep and do not use it either.

Quick file loading 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 9 years ago.
Improve this question
I have a requirement to load a file containing up to 1 million lines of string data. My first thought is to use C# 5.0 async to load the data whilst not blocking the UI thread. If the user tries to access something that relies on the data they will get a loading message.
Still I would like the fastest possible method in order to improve the user's experience.
Is the speed of reading data from the disk purely a function of the disk speed and thus StreamReader.ReadAllLines() is as performant as other c# code? Or is there something 'fancy' I can do to boost performance programmatically. This does not have to be described in detail. If so what approximate percentage improvement might be achieved?
I am purely interested in read speed and not concerned with the speed of code that may process the data once loaded.
First of all, take a look on File size, here is detailed Performance measurements

Resolving latency issues between a background thread and the UI thread in C#/WPF? [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 8 years ago.
Improve this question
I was asked this question in an interview and still not sure what the correct answer is. The question was:
"If you have a live streaming feed of data that needs to be passed from the background thread to the UI, how do you resolve latency issues between the 2 threads?"
I have read about different types of locks, where multiple threads can access an object simultaneously, however I'm not sure if this is correct as a lock might not be needed. You could just put the data on the dispatcher to send it to the UI.
Does anyone know the answer to this?
I believe the right response for this question is: What latency issues?
It's impossible to answer this question without more information - how the two threads communicate, and what latency issues exist.

Categories

Resources