C C T B H P N

Lecture #9 - Processes and Threads

Models and simple examples

Web Resourses:

UML XML, HTML Code Project Microsoft Developer's Network XML Sells Brothers C# Corner Mono Project Performance Counters

Content:

This lecture introduces threading models and a few simple examples.
Class text chapter 14.
  1. The Syllabus describes topics to be covered, reading material for you to digest before coming to class, and due dates for the assigned projects.
  2. Projects:

    Project #1, Project #2, Project #3, Project #4, Project2HelpF2018 Find Visual Studio Command Window used to test Compile.bat and Run.bat files Project #1 Grades, Project #2 Packages, Project #2 Activities
  3. Basic Windows Concepts

    If you understand these diagrams, you have a good understanding of how Windows OS works.
  4. Windows Processes

  5. Threads

    Why threads? demo
    This demonstrates that a GUI window will freeze if given a lot of processing that runs on the main thread. The solution is to use a child thread to handle all the CPU intensive processing, while the main thread responds to user events. Threads Presentation, pptx
    This presentation discusses Windows threading and synchronization constructs and compares them to facilities provided by the .Net Framework.
  6. Code Demos:

    Starting Threads
    Starting threads with ThreadStart and ParameterizedThreadStart delegates
    Basic Thread Demos
    Creating threads, locking with Lock, Monitor, and Mutex locks, another illustration of lambda closure
    Blocking Queue using Monitor
    Thread-safe blocking queue using preferred method of synchronization with Monitor
    BlockingCollection<T>
    We won't use this and won't discuss
    Queued Messages with BlockingQueue
    Communication between threads by passing messages throught BlockingQueue.
    Queued Messages with synchronized methods
    C#, like Java, has synchronized methods. We won't use them in this class.
    Wait For Event
    Use interlocked to signal type of action, Monitor to wait for a keyboard event
    Threads and Tasks
    Creation and use of threads, several threads running concurrently, threads sharing data, creation and use of Tasks, Tasks with Continuations.
    Tasks and Continuations
    Task with no result, Task with no result and continuation, Task with result, Task with result and Continuation, Task taking lambda, Task using asynch - await
    WPF Thread Demos
    Threads-SMA-MTF15
    Thread with enqueued tasks, asynchronous function with callback, asynchronous notifier, stoppable asynchronous function
    Form's BackgroundWorker
    .Net FormInvoke Demo
    WPF Dispatcher Invoke Demo
    ThreadPool Demo
  7. AppDomain Demos - Won't need for projects this year, but important for later

    • AppDomainDemo - ver 2
      Illustrates how to create a child AppDomain, load a library into it, and use the library.
    • AppDomainDemo2
      Illustrates how to establish two-way communication between parent and child AppDomains.
    • AppDomainDemo3
      Illustrates how to handle almost all the common processing errors, e.g.,
      test code intentionally throwing, divide by zero, use of null reference, and Thread.Abort().
    • CS-BlockingQueue
      This package implements a blocking queue, which you need for Project #2.
    • LoadingTests - ver 2
      Illustrates how to load test drivers, their tested code, and create and use the test driver.
      You will need to load this code into a child AppDomain. Ver 2 adds additional error handling.
    • XmlHelp
      Illustrates how to parse an XML TestRequest message.