Module 8 Enhancing User Interface Responsiveness.

Slides:



Advertisements
Similar presentations
How to Build Multi- threaded Applications in.NET Mazen S. Alzogbi Technology Specialist Microsoft Corporation.
Advertisements

An overview of… Luis Guerrero Plain Concepts
Parallel Extensions to the.NET Framework Daniel Moth Microsoft
Module 10 WPF 2-D Graphics, Multimedia, and Printing.
Developing User Interfaces with Event-driven Programming
Module 20 Troubleshooting Common SQL Server 2008 R2 Administrative Issues.
Chapter 14 Multithreading Yingcai Xiao. Multithreading is a mechanism for performing two or more tasks concurrently.  In the managed world of the common.
Intro to Threading CS221 – 4/20/09. What we’ll cover today Finish the DOTS program Introduction to threads and multi-threading.
Threads Section 2.2. Introduction to threads A thread (of execution) is a light-weight process –Threads reside within processes. –They share one address.
Virtual techdays INDIA │ 9-11 February 2011 Parallelism in.NET 4.0 Parag Paithankar │ Technology Advisor - Web, Microsoft India.
Silberschatz, Galvin and Gagne  Operating System Concepts Chapter 5: Threads Overview Multithreading Models Threading Issues Pthreads Solaris.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
Concurrency CS 510: Programming Languages David Walker.
3.5 Interprocess Communication
Daniel Moth  Parallel Computing Platform Microsoft Corporation TL26.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
Microsoft ® Official Course Monitoring and Troubleshooting Custom SharePoint Solutions SharePoint Practice Microsoft SharePoint 2013.
Windows.Net Programming Series Preview. Course Schedule CourseDate Microsoft.Net Fundamentals 01/13/2014 Microsoft Windows/Web Fundamentals 01/20/2014.
Neal Stublen Practice Solution  Create a new solution  Add a WinForms project  Add a Class Library project  Reference the library.
1 Advanced Computer Programming Concurrency Multithreaded Programs Copyright © Texas Education Agency, 2013.
Module 12 Installing and Upgrading to SharePoint 2010.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Concurrency in Android with.
1 Lecture 4: Threads Operating System Fall Contents Overview: Processes & Threads Benefits of Threads Thread State and Operations User Thread.
Module 11 Control Customization. Module Overview Overview of Control Authoring Creating Controls Managing Control Appearance by Using Visual States Integrating.
Microsoft ® Official Course Module XA Using Windows PowerShell ®
Module 7: Fundamentals of Administering Windows Server 2008.
Week 3, Day 1: Processes & Threads Return Quiz Processes Threads Lab: Quiz Lab 3: Strategy & Factory Patterns! SE-2811 Slide design: Dr. Mark L. Hornick.
Module 7 Reading SQL Server® 2008 R2 Execution Plans.
Parallel Extensions A glimpse into the parallel universe By Eric De Carufel Microsoft.NET Solution Architect at Orckestra
Monitoring Windows Server 2012
Module 12 Attached Properties and Behaviors in WPF.
Module 10 Administering and Configuring SharePoint Search.
Lecture 21 Parallel Programming Richard Gesick. Parallel Computing Parallel computing is a form of computation in which many operations are carried out.
Module 14 Monitoring and Optimizing SharePoint Performance.
Module 6 Securing Content. Module Overview Administering SharePoint Groups Implementing SharePoint Roles and Role Assignments Securing and Auditing SharePoint.
Concurrent Programming and Threads Threads Blocking a User Interface.
Module 7 Data Binding to Collections. Module Overview Binding to Collections of Objects Using Collection Views Create Master-Detail User Interfaces Using.
Last Lecture objective C memory management rules Wrote our first iPhone app a quiz app xib and nib files and interface editor MVC pattern IBOutlet IBAction.
Configuring Workflows Module 4. Overview  Understanding Workflows  Using Default Workflows  Creating Workflow Instances.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 Reusing threads.
Module 13 Animations in WPF. Module Overview Using Animations Using Triggers Implementing Data Visualizations.
Module 14 Application Settings, State, and Life Cycle.
Building State of the art presentation tiers Nauzad Kapadia
Module 3 Designing and Developing a User Interface.
Module 4 Taking Control of the User Interface. Module Overview Sharing Logical Resources in an Application Creating Consistent User Interfaces by Using.
Module 9 Planning and Implementing Monitoring and Maintenance.
1 OS Review Processes and Threads Chi Zhang
Threads. Thread A basic unit of CPU utilization. An Abstract data type representing an independent flow of control within a process A traditional (or.
CSE 434: Computer Networks Project Single vs. Per Connection vs. Pooling Threading Techniques Dominic Hilsbos, Dorothy Johnson, Chris Volpe, Andy Wong,
Module 5: Managing Content. Overview Publishing Content Executing Reports Creating Cached Instances Creating Snapshots and Report History Creating Subscriptions.
Java Threads 1 1 Threading and Concurrent Programming in Java Threads and Swing D.W. Denbo.
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
Functional Processing of Collections (Advanced) 6.0.
Threads and Swing Multithreading. Contents I. Simulation on Inserting and Removing Items in a Combo Box II. Event Dispatch Thread III. Rules for Running.
Event Based Simulation of The Backfilling Algorithm OOP tirgul No
Advanced Topics in Concurrency and Reactive Programming: Asynchronous Programming Majeed Kassis.
Async or Parallel? No they aren’t the same thing!
Chapter 4: Multithreaded Programming
Lecture 28 Concurrent, Responsive GUIs
Understand Windows Forms Applications and Console-based Applications
Staying Afloat in the .NET Async Ocean
Chapter 4: Threads.
12 Asynchronous Programming
Gathering User Input Event Handling Create Dynamic controls
Android Topics Asynchronous Callsbacks
Android Topics Threads and the MessageQueue
Chapter 4 Threads, SMP, and Microkernels
Lecture 20 Parallel Programming CSE /8/2019.
Threads CSE 2431: Introduction to Operating Systems
UI Elements 2.
Presentation transcript:

Module 8 Enhancing User Interface Responsiveness

Module Overview Implementing Asynchronous Processes Implementing Responsive User Interfaces

Lesson 1: Implementing Asynchronous Processes Understanding Threading and Asynchronous Processing Implementing Asynchronous Processing by Using the Dispatcher Class Implementing Asynchronous Processing by Using the ThreadPool Class Implementing Asynchronous Processing by Using the BackgroundWorker Class Implementing Asynchronous Processing by Using the TPL

Threading: Understanding Threading and Asynchronous Processing All WPF applications use two threads: Managing the user interface Rendering visual elements The Dispatcher class handles thread affinity Thread affinity: You can only use a WPF object on the thread on which it was created Implement asynchronous processing by using: The Dispatcher class The ThreadPool class The BackgroundWorker class The Task Parallel Library The Dispatcher class The ThreadPool class The BackgroundWorker class The Task Parallel Library

Two approaches: Implementing Asynchronous Processing by Using the Dispatcher Class Schedule prioritized work items by using the Dispatcher's message loop myControl.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action(UserInterfaceUpdate)); myControl.Dispatcher.BeginInvoke( DispatcherPriority.Background, new Action(UserInterfaceUpdate)); Schedule periodic execution of work items by using a DispatcherTimer myTimer = new DispatcherTimer( DispatcherPriority.Background, myControl.Dispatcher); myTimer.Interval = TimeSpan.FromSeconds(2); myTimer.Tick += new EventHandler( delegate(object s, EventArgs a) { // Update the user interface. }); myTimer.Start(); myTimer = new DispatcherTimer( DispatcherPriority.Background, myControl.Dispatcher); myTimer.Interval = TimeSpan.FromSeconds(2); myTimer.Tick += new EventHandler( delegate(object s, EventArgs a) { // Update the user interface. }); myTimer.Start();

Implementing Asynchronous Processing by Using the ThreadPool Class The ThreadPool class: Provides a pool of worker threads Manages thread creation and reuse Has 250 worker threads per processor by default Queues work items until a thread becomes available Cannot access the UI thread public static void Main() { ThreadPool.QueueUserWorkItem( new WaitCallback(DoWork)); } private static void DoWork( object parameter) { // Perform background task. } public static void Main() { ThreadPool.QueueUserWorkItem( new WaitCallback(DoWork)); } private static void DoWork( object parameter) { // Perform background task. }

Implementing Asynchronous Processing by Using the BackgroundWorker Class You must not try to manipulate UI objects in your DoWork delegate The RunWorkerCompleted and ProgressChanged event handlers are executed on the creation thread The DoWork delegate is executed on a background thread

Parallel foreach loop Parallel tasks Parallel LINQ Parallel foreach loop Parallel tasks Parallel LINQ Sequential foreach loop Sequential tasks Sequential LINQ Sequential foreach loop Sequential tasks Sequential LINQ Implementing Asynchronous Processing by Using the TPL foreach (var item in source) { DoSomething(item); } foreach (var item in source) { DoSomething(item); } Parallel.ForEach( source, item => DoSomething(item)); Parallel.ForEach( source, item => DoSomething(item)); DoSomething(); DoSomethingElse(); DoSomething(); DoSomethingElse(); Parallel.Invoke( () => DoSomething(), () => DoSomethingElse()); Parallel.Invoke( () => DoSomething(), () => DoSomethingElse()); var evenNums = from num in source where Compute(num) > 0 select num; var evenNums = from num in source where Compute(num) > 0 select num; var evenNums = from num in source.AsParallel() where Compute(num) > 0 select num; var evenNums = from num in source.AsParallel() where Compute(num) > 0 select num;

Lesson 2: Implementing Responsive User Interfaces Understanding Responsive User Interfaces Selecting an Asynchronous Processing Approach

Understanding Responsive User Interfaces An unresponsive application: Does not respond to user input Will not process UI updates Will present the busy cursor May appear to have crashed May display (Not Responding) in title bar May present entirely black or white window contents

Selecting an Asynchronous Processing Approach Performing too much work on the UI thread: Performing too much work on the UI thread: Use the ThreadPool class Use the Task Parallel Library Use the BackgroundWorker class Thread starvation: Use the ThreadPool class Waiting for a process to return: Use the ThreadPool class Use the Task Parallel Library Use the BackgroundWorker class The BackgroundWorker class is the only approach that directly enables you to report progress and marshals onto the UI thread for progress and completion events

Lab: Enhancing Application Performance Exercise 1: Choosing an Asynchronous Programming Strategy Exercise 2: Implementing Asynchronous Operations Exercise 3: Parallelizing Tasks Logon information Estimated time: 60 minutes

Lab Scenario You have been asked to create a master view for all work orders in the system. This large data set must be responsive in the UI at all times and must also provide filtering and sorting support. You will evaluate different asynchronous programming techniques to determine the optimal approach. In addition, you must calculate some statistics for each data operation, which will be calculated in parallel.

Lab Review Review Questions How do you update the UI when you implement a long- running task as an asynchronous operation? How do you perform multiple tasks concurrently?

Module Review and Takeaways Review Questions Common Issues and Troubleshooting Tips