Please enable JavaScript.
Coggle requires JavaScript to display documents.
C# Advanced - Coggle Diagram
C# Advanced
Threads
-
-
Each thread has a scheduling priority and maintains a set of structures the system uses to save the thread context when the thread's execution is paused.
-
BackgroundWorker
-
DoWork, ProgressChanged, RunWorkCompleted are the methods in it. Supports AutoCancellation
-
-
Thread-Safety
-
-
-
Deadlock
Threads holds and resource and following can happen - Mutual Exclusion, Hold and Wait, No Preemption or Circular Wait
Semaphore
C# semaphore allows only a limited number of threads to enter into a critical section. Semaphore is mainly used in scenarios where we have limited number of resources and we have to limit the number of threads that can use it. _pool = new Semaphore(0,3). _pool.WaitOne();. _pool.Release(3)
Threads run on same processor or Core. Thus, Time Slicing or Context Switching happens
Tasks
-
-
The Task class represents a single operation that does not return a value and that usually executes asynchronously.
- Task t = new Task( () => { try { }
catch(AggregatorException ex) { } }.
- Task[] tasks = new Tasks[10]; Task.WaitAll(tasks).
- Task t = Task.Factory.StartNew( () => {} ),, t.Wait();
- Action<object> action = (object o) => { c.wl(o); }; Task t = new Task(action, "name"); t.Start();
- t.RunSynchronously() will run the task synchronously
-
Task and TPL are out Parallel Processing. Thread and Async are about Concurrency (Running things on same thread). In TPL Threads are independent whereas Async are dependent.
-