SlideShare a Scribd company logo
1 of 28
Multithreading in C# MedhatDawoud MedhatDawoud@gmail.com www.medhatdawoud.com
Agenda Introduction. 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  How? (Stories to Clear)
What is Multitasking ? A Little Demo for two Methods WithoutMultitasking
What is Multitasking ? So,  Whatis a Thread? And 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 Synchronization 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  Deadlock* * 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 : ,[object Object]
What’s Multithreading.
Problems face us and how to solve them.

More Related Content

What's hot

Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread SynchronizationBenj Del Mundo
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVASURIT DATTA
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web ApplicationRishi Kothari
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handlingkamal kotecha
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in javaRaghu nath
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Javaparag
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVAVINOTH R
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in javapooja kumari
 
Chapitre 6 traitement des exceptions
Chapitre 6  traitement des exceptionsChapitre 6  traitement des exceptions
Chapitre 6 traitement des exceptionsAmir Souissi
 
Threads And Synchronization in C#
Threads And Synchronization in C#Threads And Synchronization in C#
Threads And Synchronization in C#Rizwan Ali
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...Edureka!
 

What's hot (20)

Presentation1
Presentation1Presentation1
Presentation1
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Java Thread Synchronization
Java Thread SynchronizationJava Thread Synchronization
Java Thread Synchronization
 
Java exception
Java exception Java exception
Java exception
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Java 8 date & time api
Java 8 date & time apiJava 8 date & time api
Java 8 date & time api
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Developing an ASP.NET Web Application
Developing an ASP.NET Web ApplicationDeveloping an ASP.NET Web Application
Developing an ASP.NET Web Application
 
Java Exception handling
Java Exception handlingJava Exception handling
Java Exception handling
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Multithreading In Java
Multithreading In JavaMultithreading In Java
Multithreading In Java
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
JavaFX Overview
JavaFX OverviewJavaFX Overview
JavaFX Overview
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Chapitre 6 traitement des exceptions
Chapitre 6  traitement des exceptionsChapitre 6  traitement des exceptions
Chapitre 6 traitement des exceptions
 
Threads And Synchronization in C#
Threads And Synchronization in C#Threads And Synchronization in C#
Threads And Synchronization in C#
 
Packages in java
Packages in javaPackages in java
Packages in java
 
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
jQuery Tutorial For Beginners | Developing User Interface (UI) Using jQuery |...
 

Viewers also liked

Viewers also liked (20)

Threading in c#
Threading in c#Threading in c#
Threading in c#
 
Threading
ThreadingThreading
Threading
 
multi threading
multi threadingmulti threading
multi threading
 
Threads c sharp
Threads c sharpThreads c sharp
Threads c sharp
 
C# Advanced L04-Threading
C# Advanced L04-ThreadingC# Advanced L04-Threading
C# Advanced L04-Threading
 
Intro To .Net Threads
Intro To .Net ThreadsIntro To .Net Threads
Intro To .Net Threads
 
Threads c sharp
Threads c sharpThreads c sharp
Threads c sharp
 
Thread
ThreadThread
Thread
 
Multi threading design pattern
Multi threading design patternMulti threading design pattern
Multi threading design pattern
 
Asynchronous Programming with C#
Asynchronous Programming with C#Asynchronous Programming with C#
Asynchronous Programming with C#
 
Delegates and events
Delegates and events   Delegates and events
Delegates and events
 
Real time web
Real time webReal time web
Real time web
 
Concurrency
ConcurrencyConcurrency
Concurrency
 
Triggers en SQL Server
Triggers en SQL ServerTriggers en SQL Server
Triggers en SQL Server
 
Backgroundworker
Backgroundworker Backgroundworker
Backgroundworker
 
[Winform] Visual studio C# 2012 upload ftp
[Winform] Visual studio C# 2012 upload ftp[Winform] Visual studio C# 2012 upload ftp
[Winform] Visual studio C# 2012 upload ftp
 
Generics C#
Generics C#Generics C#
Generics C#
 
[Winform] Visual studio C# 2012 Setting themes with telerik themes library
[Winform] Visual studio C# 2012 Setting themes with telerik themes library[Winform] Visual studio C# 2012 Setting themes with telerik themes library
[Winform] Visual studio C# 2012 Setting themes with telerik themes library
 
C# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programmingC# 5 deep drive into asynchronous programming
C# 5 deep drive into asynchronous programming
 
Multithreading Design Patterns
Multithreading Design PatternsMultithreading Design Patterns
Multithreading Design Patterns
 

Similar to Threading in C#

C# interview-questions
C# interview-questionsC# interview-questions
C# interview-questionsnicolbiden
 
25 java tough interview questions
25 java tough interview questions25 java tough interview questions
25 java tough interview questionsArun Banotra
 
Lecture #2 threading, networking & permissions final version #2
Lecture #2  threading, networking & permissions final version #2Lecture #2  threading, networking & permissions final version #2
Lecture #2 threading, networking & permissions final version #2Vitali Pekelis
 
1.17 Thread in java.pptx
1.17 Thread in java.pptx1.17 Thread in java.pptx
1.17 Thread in java.pptxTREXSHyNE
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Sagar Verma
 
Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...
Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...
Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...Codemotion
 
C# classes
C#   classesC#   classes
C# classesTiago
 
Comparing different concurrency models on the JVM
Comparing different concurrency models on the JVMComparing different concurrency models on the JVM
Comparing different concurrency models on the JVMMario Fusco
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in androidRakesh Jha
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternNishith Shukla
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsLalit Kale
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural PatternsSameh Deabes
 
Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101Tim Penhey
 

Similar to Threading in C# (20)

Java Threads
Java ThreadsJava Threads
Java Threads
 
C# interview
C# interviewC# interview
C# interview
 
C# interview-questions
C# interview-questionsC# interview-questions
C# interview-questions
 
25 java tough interview questions
25 java tough interview questions25 java tough interview questions
25 java tough interview questions
 
Lecture #2 threading, networking & permissions final version #2
Lecture #2  threading, networking & permissions final version #2Lecture #2  threading, networking & permissions final version #2
Lecture #2 threading, networking & permissions final version #2
 
1.17 Thread in java.pptx
1.17 Thread in java.pptx1.17 Thread in java.pptx
1.17 Thread in java.pptx
 
All of Javascript
All of JavascriptAll of Javascript
All of Javascript
 
java_threads.ppt
java_threads.pptjava_threads.ppt
java_threads.ppt
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
 
Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...
Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...
Mario Fusco - Comparing different concurrency models on the JVM | Codemotion ...
 
C# classes
C#   classesC#   classes
C# classes
 
Comparing different concurrency models on the JVM
Comparing different concurrency models on the JVMComparing different concurrency models on the JVM
Comparing different concurrency models on the JVM
 
Basic java part_ii
Basic java part_iiBasic java part_ii
Basic java part_ii
 
Multithreading and concurrency in android
Multithreading and concurrency in androidMultithreading and concurrency in android
Multithreading and concurrency in android
 
Jump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design PatternJump start to OOP, OOAD, and Design Pattern
Jump start to OOP, OOAD, and Design Pattern
 
Jump Start To Ooad And Design Patterns
Jump Start To Ooad And Design PatternsJump Start To Ooad And Design Patterns
Jump Start To Ooad And Design Patterns
 
All of javascript
All of javascriptAll of javascript
All of javascript
 
GoF Design patterns I: Introduction + Structural Patterns
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
 
Multithreading 101
Multithreading 101Multithreading 101
Multithreading 101
 
Unusual C# - OOP
Unusual C# - OOPUnusual C# - OOP
Unusual C# - OOP
 

More from Medhat Dawoud

Using Git and BitBucket
Using Git and BitBucketUsing Git and BitBucket
Using Git and BitBucketMedhat Dawoud
 
Introduction to linux
Introduction to linuxIntroduction to linux
Introduction to linuxMedhat Dawoud
 
Intro to t sql – 3rd session
Intro to t sql – 3rd sessionIntro to t sql – 3rd session
Intro to t sql – 3rd sessionMedhat Dawoud
 
Intro to T-SQL - 1st session
Intro to T-SQL - 1st sessionIntro to T-SQL - 1st session
Intro to T-SQL - 1st sessionMedhat Dawoud
 
Intro to T-SQL – 2nd session
Intro to T-SQL – 2nd sessionIntro to T-SQL – 2nd session
Intro to T-SQL – 2nd sessionMedhat Dawoud
 
Mesh cloud (road to mongoDB)
Mesh cloud (road to mongoDB)Mesh cloud (road to mongoDB)
Mesh cloud (road to mongoDB)Medhat Dawoud
 

More from Medhat Dawoud (11)

Using Git and BitBucket
Using Git and BitBucketUsing Git and BitBucket
Using Git and BitBucket
 
Introduction to linux
Introduction to linuxIntroduction to linux
Introduction to linux
 
Select your career
Select your careerSelect your career
Select your career
 
Intro to t sql – 3rd session
Intro to t sql – 3rd sessionIntro to t sql – 3rd session
Intro to t sql – 3rd session
 
Intro to T-SQL - 1st session
Intro to T-SQL - 1st sessionIntro to T-SQL - 1st session
Intro to T-SQL - 1st session
 
Intro to T-SQL – 2nd session
Intro to T-SQL – 2nd sessionIntro to T-SQL – 2nd session
Intro to T-SQL – 2nd session
 
Mesh cloud (road to mongoDB)
Mesh cloud (road to mongoDB)Mesh cloud (road to mongoDB)
Mesh cloud (road to mongoDB)
 
Before start
Before startBefore start
Before start
 
DevMix Startup
DevMix StartupDevMix Startup
DevMix Startup
 
How to python
How to pythonHow to python
How to python
 
Program threats
Program threatsProgram threats
Program threats
 

Recently uploaded

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 

Recently uploaded (20)

Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 

Threading in C#

  • 1. Multithreading in C# MedhatDawoud MedhatDawoud@gmail.com www.medhatdawoud.com
  • 2. Agenda Introduction. What’s Multithreading ? Threads types ? Threading in C# ? Thread Class functionality. Problems and solutions .
  • 3. Introduction Do you like to be professional ? What is the target of this session ? A word by the history. Before multithreading.
  • 4. What is Multitasking ? Operating Systems do this for us How? (Stories to Clear)
  • 5. What is Multitasking ? A Little Demo for two Methods WithoutMultitasking
  • 6. What is Multitasking ? So, Whatis a Thread? And Howit works ?
  • 7. 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 .
  • 8. Multithreading in C# C# support Multitasking strongly. Multithreading == Multitasking. using System.Threading* . Using Thread class. * A built in namespace in .NET framework
  • 9. Thread Class Functionality This class has very important Static members * * Static members is that you call directly without objects
  • 10. Thread (Static Members) Static Properties
  • 11. Thread (Static Members) Static Methods
  • 12. Thread (Static Members) Show Demo* * A simple program Written in C# to Clear all ideas of Thread Class
  • 13. Problems that will face us Non-technical Example The Television between you and your sister 
  • 14. Problems that will face us A TechnicalExample
  • 15. 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).
  • 16. 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.
  • 17. Give a solution ?? Some one say : Stop sharing device It sounds very funny 
  • 18. The perfect solution is Synchronization The locking mechanism
  • 19. 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 .
  • 20. Another problem One of the problems that Threads cause is Deadlock* * It means that one thread might wait infinite period.
  • 21. 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 ?
  • 22. 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
  • 23. 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.
  • 24. 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 .
  • 25. So, what is the solution ? The only Way is To be very Carefulwhen usingmultiple locks .
  • 26.
  • 28. Problems face us and how to solve them.
  • 29.