avoid doing AsyncOperation.Result parent method waits for Result while child method waits for parent thread to take control, after being done with async I/O both waits deadlock Further read:
https://medium.com/rubrikkgroup/understanding-async-avoiding-deadlocks-e41f8f2c6f5d https://stackoverflow.com/questions/15021304/an-async-await-example-that-causes-a-deadlock
Asynchronous programming patterns in .NET:
Asynchronous Programming Model (BeginOperation/EndOperation) Event-based Asynchronous Pattern (invoke event with result from async job) Task-based Asynchronous Pattern (Task<>) Ways of achieving asynchronous code in .NET
async, await Task class API (Run, WhenAll, WhenAny, etc.) ThreadPool.QueueUserWorkItem(ThreadProc); Further read:
async/await in .NET
https://learn.microsoft.com/en-us/dotnet/standard/asynchronous-programming-patterns/
There are two types of asynchronous operations in .NET.
I/O bound
CPU bound
For I/O bound async/await syntax should be used. TPL should not be used for this. async methods does not spawns new thread to hand le I/O work asynchronously.
For CPU bound operations TPL should be used (Task.Run). This spawns new thread. Performance testing should be done to check if overhead of new thread and context switching is not greater than actual work to be done.
· 143 words · ~1 min read
· updated
· in .NET, interview
informs GC that object does not need to be added to finalizer queue
finalizer execution is not deterministic and objects can live for long time in queue - this is optimization technique
to make sure that object disposes of any unamanaged resources even if Dispose will be not called we need to implement finalizer
Basically finalizer execution time is not deterministic. We cannot predict when this will be called and till that time - object is existing and still taking memory space. Since we are controlling creation and disposal of those resources we can say to GC: ‘Do not worry about that! It already had been taken care of!’. So this way object will be destroyed sooner, leaving this space to be used by something else possibly.
MyResource object have pointer which is unmanaged. This is why this class should implement IDisposable interface. Implementation should be correct according to recommended pattern (see below for documentation).
Closed What is asynchronous programming? What is TDD What is BDD What is DDD Open - to consider for yourself Interesting technical problem you solved lately Interesting technical problem you solved during your career What is the process of the MR/PR change review for you What is great success you accomplished lately? What skill did you improved lately? What is your greatest failure during your career? What was your biggest mistake?
software design approach software should be driven by business domain pieces of software should match the business domain goals: domain is primary focus complex design should base on model of the domain devs and business should continuously work on refining this model to address changes in business common language for defining a business model of the domain complex logic should be abstracted to domain Further read:
https://en.wikipedia.org/wiki/Domain-driven_design
based on TDD better collaboration between devs, QAs and business than TDD behavioral tests first, implementation second behavioral tests should be easy to understand, simple those tests should be written in specific language, possible to understood by business combines idea of unit tests naming, acceptance tests standard agile framework (As a XXX I want YY to achieve ZZ), and acceptance criteria with Gherkin Further read:
https://en.wikipedia.org/wiki/Behavior-driven_development
Test-driven development
software requirements are converted to tests cases *before* actual implementation implementation is done against all those test cases opposing to first writing an implementation then tests cases Further read:
https://en.wikipedia.org/wiki/Test-driven_development
software often waits for some I/O operation to complete (file operation, network call, database query etc.)
we can use this time for something productive instead to wait for data to be available or I/O operation to be completed
with asynchronous programming user can work in the meantime
not waiting for I/O operations synchronously enhances user experience
Of course this problem is much more complex. Modern software operates on much more different PC architecture than 20 years ago. Nowadays software must be asynchronous to appear more user friendly and to made better use of modern multi CPU architecture. Right now complex, professional software uses multiple processes, threads on multiple CPUs (CPU you buy is not really *single* CPU) or even utilize GPU for more complex computations (like i.e. video editing software). Before that we mostly had single threaded desktop applications that had ‘please wait’ or ’loading’ pop ups. Right now this is song of the past really and to achieve better User Interfaces that allow to edit tag of your post without changing whole post. With mobile devices on the rise and sometimes lousy cellular network those kind of designs would not be sensible or sometimes impossible to implement. Did you ever happened to reenter some chunk of data into some software because you lost it? Maybe network was down? Or you hit back button by mistake? Right now it belongs to past mostly. All of those would be hard to do with synchronous operations. Right now people are bit spoiled and they tend to leave the page/application if it appears to be slow and not every company can sell ‘one-in-the-market-necessary-for-your-work-software’ that you will be forced to use. And this is why we have asynchronous operations and this is why we have asynchronous programming model that allows us to program such operations.
Delegates can be converted easily to another type if you know types of those delegates. But if you do not know it is impossible without really complicated code.
Important note: this should work well with newer version of Xamarin (2.3.3). If you cannot update for some reason this article will explain workaround.
Introduction
In previous article I explained how to detect show and hide events of software keyboard in Xamarin Android. I did it in my project because of the fact that some of text boxes was hidden by software keyboard that suppose to edit contents of those text boxes. In this article I will explain how to work around this issue in some older versions of Xamarin.