Writing Mobile Code Essential Software Engineering for Building Mobile Applications [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Writing Mobile Code Essential Software Engineering for Building Mobile Applications [Electronic resources] - نسخه متنی

Ivo Salmre

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید











Summary


Background threads can be useful in improving the end user's experience with your mobile application by increasing the responsiveness of the user interface, but only if used properly. Use background threads sparingly, specifically, and only when they solve a real application responsiveness problem that cannot be solved in the foreground thread. It is best to approach your application's design using a single-threaded model and only add background processing when the need proves itself.

Great care is warranted when writing background threading code and designing classes that need to be accessed from multiple threads. It is very useful to document your application's code to explicitly indicate which pieces are going to be accessed by multiple threads and as importantly which are not. Keep the number of classes, functions, properties, and member variables that need to be shared between multiple threads as small as possible and apply rigorous design, review, testing, and documentation efforts to these parts.

As with other aspects of design, using state machines can be beneficial when approaching asynchronous processing. State machines are a great way to manage background execution. A state machine allows for communication between different threads. They enable background threads to advertise their processing progress as well as allow other threads to request things from the background thread such as requesting the aborting of the background work. Encapsulating a background task in a class is a good abstraction and allows you to think of the background task as a logical entity with defined inputs and outputs.

In almost all cases, it is a good idea to have only one thread that drives the user interface; this is the main thread of your application. The user interface thread can periodically poll background tasks to see how they are progressing and relay this information to the user as appropriate. Alternatively, background threads can push this information to the user interface thread via a cross-thread communications mechanism such as the .NET Compact Frameworks Control.Invoke() mechanism.

Threads are a very useful but sophisticated concept. Like any advanced technique, there is a tendency to over-apply the use of threading. Unnecessary threads slow down overall application performance and overly complex threading models make code hard to maintain and debug. Use threads only when a proven need exists and then use them in the simplest manner possible. Following these simple guidelines will allow you to get the benefits of multithreading while avoiding the many potential pitfalls of concurrent streams of code execution.


/ 159