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
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
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 .