# Exam 3 Review
* Controls
- **ImageList, ListView, TreeView, PictureBox**
 ImageList The Windows Forms ImageList component is used to store images, which can then be displayed by controls. An image list allows you to write code for a single, consistent catalog of images.
 ListView Represents a Windows list view control, which displays a collection of items that can be displayed using one of four different views.

TreeView Displays a hierarchical collection of labeled items, each represented by a TreeNode.

PictureBox Represents a Windows picture box control for displaying an image.
- Embedding images in exe as a resource
* Asynchronous programming
- Locking up app
- Unresponsive apps are usually detected by the OS, and the user is typically given the choice to close them down

- UI thread (message loop) vs background thread
- A GUI app uses a background thread to perform time-consuming operations asynchronously so the UI thread can continue to process messages
- Usability issues
- Use background threads when operation might be > one second
- Use activity indicator for activity that completes in < 5 seconds, otherwise use progress bar
async, await
- **async** - Used to indicate that the method is asynchronous.
- **await** - Applied to a task in an asynchronous method to suspend the execution of the method until the awaited task completes
- May only be used in async method
- Can be used more than once in the same async method.
- Task – thread pool, starting and cancelling
Task.Run(), CancellationTokenSource
- Task class represents an asynchronous operation
- Async methods return a Task or a Task<TResult>
```C#
async Task<string> TaskOfTResult_MethodAsync()
{
string s;
// . . .
// Return statement specifies a string result
return s;
}
```
- Use Task if the method has no return statement or doesn't return a value.
```C#
async Task Task_MethodAsync()
{
// . . .
// Method has no return statement
}
// Call to Task_MethodAsync
Task returnedTask = Task_MethodAsync();
await returnedTask;
// or in a single statement
await Task_MethodAsync();
```
- Updating UI with background thread
```C#
private async void myButton_Click(object sender, EventArgs e)
{
progressBar1.Visible = true;
await Task.Run(() =>
{
for (int i = 1; i <= 10; i++)
{
// Perform a time-consuming operation
System.Threading.Thread.Sleep(500);
// Run on UI thread
try
{
Invoke((Action)delegate ()
{
progressBar1.Value = i * 10;
});
}
catch (ObjectDisposedException)
{
// The form was closed before the thread completed. No big deal.
}
}
});
progressBar1.Visible = false;
}
```
- Control.Invoke(), ObjectDisposedException
- **Control.Invoke(Delegate method)** - Executes the delegate on the UI thread
delegate void System.Action() -
- **Delegate** for a method with no params or return value
- **ObjectDisposedException** - Exception that is thrown if MainForm is disposed when accessing controls that belong to MainForm
* Project 1: Photo Editor
- Implementation
* Designing with the Mind in Mind
- Chapter 5 – Our Perception is Biased
Fovea and peripheral vision
Examples from UIs
Making messages visible, make targets “pop”
- Chapter 6 – Reading is Unnatural
Reading difficulties
- typefaces, shapes,tiny fonts,text on noisy background, information buried in repetition,centered text,
--
Feature-driven vs. context-driven
- information buried in repetition
Skilled vs. unskilled reading
Things that disrupt reading
- Much of the reading equired by software is unnecessary
- Poor information
- Uncommon or unfamiliar vocabulary.
- difficult scripts and typefaces
- tiny fonts
- Text on noisy background
- Information buried in repetition
- Centered text