• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Threading in C#

Threading in C#



this presentation was shown in 25/12/2010 at perfect training center

this presentation was shown in 25/12/2010 at perfect training center



Total Views
Views on SlideShare
Embed Views



3 Embeds 63

http://med7at.wordpress.com 61
https://www.linkedin.com 1
http://www.linkedin.com 1



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment

    Threading in C# Threading in C# Presentation Transcript

    • Multithreading in C#
    • Agenda
      What’s Multithreading ?
      Threads types ?
      Threading in C# ?
      Thread Class functionality.
      Problems and solutions .
    • Introduction
      Do you like to be professional ?
      What is the target of this session ?
      A word by the history.
      Before multithreading.
    • What is Multitasking ?
      Operating Systems do this for us
      (Stories to Clear)
    • What is Multitasking ?
      A Little Demo for two Methods
    • What is Multitasking ?
      Whatis a Thread?
      Howit works ?
    • Threads types
      Foreground VS background .
      The Threads is by default foreground .
      But you can make it background by assigning a simple property (IsBackground) to true .
    • Multithreading in C#
      C# support Multitasking strongly.
      Multithreading == Multitasking.
      using System.Threading* .
      Using Thread class.
      * A built in namespace in .NET framework
    • Thread Class Functionality
      This class has very important
      Static members *
      * Static members is that you call directly without objects
    • Thread (Static Members)
      Static Properties
    • Thread (Static Members)
      Static Methods
    • Thread (Static Members)
      Show Demo*
      * A simple program Written in C# to Clear all ideas of Thread Class
    • Problems that will face us
      Non-technical Example
      The Television
      between you and your sister 
    • Problems that will face us
      A TechnicalExample
    • Remember that
      in our case (Multithreading ) the shared device is theCPU*
      which cannot serve more than one request in one single moment.
      So, how it help us in making multitasking applications???
      * Central Processing Unit (Processor).
    • Warning !!
      Don’t use Multiple threads except it is required not to make the CPU busy with transitions between threads instead of serving the instructions of the threads itself.
    • Give a solution ??
      Some one say :
      Stop sharing device
      It sounds very funny

    • The perfect solution is
      The locking mechanism
    • What is The locking mechanism?
      The locking mechanism is how to lock the use of an object temporarily while one thread is using it.
      Use the C# keyword Lock .
      Simple Demo .
    • Another problem
      One of the problems that Threads cause is
      * It means that one thread might wait infinite period.
    • Deadlock With An Example
      Thread 1 lock object A then lock object B
      Thread 2 lock object B then lock object A
      So, What will happen ?
    • Deadlock With An Example
      Thread 1 will lock objectA
      Thread 2 willlockobjectB
      Then , thread1 waiting for object B to be released from thread2 that waiting for object A from thread1
    • Deadlock With An Example
      So, the program will deadlock at this fragment of code because non of both threads will leave the object until it got the other and end working.
    • Deadlock ?
      Also exist in database servers and operating systems.
      This kind of bugs is Very difficult to be detected because it give no error message in runtime and has no exception handling .
      Just the program is stop responding .
    • So, what is the solution ?
      The only Way is
      To be very Carefulwhen
      usingmultiple locks .
    • Summary
      To day we know :
      • What before Multithreading.
      • What’s Multithreading.
      • Problems face us and how to solve them.
      • Synchronization and locking mechanism.
    • Thanks