V3nom's
  • Welcome
  • Getting Started
    • CEH v13
    • Basics of Networking
      • Network Models
        • Application Layer in OSI ->
        • Presentation Layer in OSI ->
          • Comprehensive list of character encoding formats
        • Session Layer in OSI ->
        • Transport Layer in OSI ->
        • Network Layer in OSI ->
        • Data Link Layer in OSI ->
        • Physical Layer ->
    • Arch Linux Installation Guide
    • How to add VBoxLinuxAdditions.run in Debian Based Linux Distros
    • C# Programming Language
  • Research Papers
    • Word Embedding for Anomaly Detection
    • Build your own Redis
    • Blockchain Technology
    • Interactive blocks
    • OpenAPI
    • Integrations
  • Risk Analysis & Mitigation Notes
    • Risk Analysis & Mitigation
      • Unit 1: An Introduction to Risk Management
      • Unit 2: The Threat Assessment Process
      • Unit 3: Vulnerability Issues
      • Unit 4 ( Risk Analysis & Mitigation )
      • Unit 5 ( Risk Analysis & Mitigation )
  • Ethical Hacking
    • Ethical Hacking Syllabus
      • Unit I: Introduction ( English )
      • Unit I: Introduction ( Hinglish )
      • Unit II: The Business Perspective ( English )
      • Unit II: The Business Perspective ( Hinglish )
      • Unit III: Preparing for a Hack ( English )
      • Unit III: Preparing for a Hack ( Hinglish )
      • Unit IV: Enumeration ( English )
      • Unit IV: Enumeration ( Hinglish )
      • Unit V: Deliverables ( English )
      • Unit V: Deliverables ( Hinglish )
  • .NET Framework Notes
    • .NET Framework Syllabus
      • Unit - I ( Hinglish Version )
      • Unit - I ( English - Version for exams )
      • Unit - II ( Hinglish Version - For Understanding )
      • Unit - II (English Version - for papers)
      • Unit - III ( Hinghlish Version )
      • Unit - III ( English - Version )
      • Unit - IV ( Hinglish Version )
      • Unit - IV ( English Version )
      • Unit - V ( Hinglish Version )
      • Unit - V ( English Version )
  • IOT
    • unit 1
    • unit 2
    • unit 3
    • unit 4
    • unit 5
  • AD-Hoc and Wireless Networks
    • Unit 1 ( Hinglish )
    • unit 2 Hinglish
    • All assignments answers with questions
    • Mind Maps for All Questions
    • Page
  • Distributed Systems
    • Unit 1
    • Unit 2
    • Unit 3
    • Unit 4
    • Unit 5
  • Group 1
    • 1’s and 2’s Complement
    • Direct Memory Access
    • Register Transfer Level
    • Interrupt-Based Input/Output (I/O)
    • Memory and CPU Design
    • Instruction Cycle
    • Addressing Modes
    • Pipelining
    • Three Types of Hazards
    • All Types of Differences Tables
    • Parallel Processing
    • Addition/Subtraction Conversion
    • Data Representation
    • Page 1
Powered by GitBook
On this page
  • Assemblies in C#
  • Types of Assemblies:
  • Global Assembly Cache (GAC):
  • Threads in C#
  • Creating and Managing Threads:
  • Thread Pooling:
  • Thread Contexts and Concurrency
  • Contexts:
  • Concurrency:
  • Synchronization:
  • AppDomains
  • AppDomains kyun use karein?
  • Creating and Managing AppDomains:
  • Processes in C#
  • Process Class:
  • Concurrency and Synchronization
  • Common Synchronization Mechanisms:
  • Summary
  1. .NET Framework Notes
  2. .NET Framework Syllabus

Unit - III ( Hinghlish Version )

Assemblies in C#

Assembly C# mein ek compiled code library hoti hai jo deployment, versioning, aur security ke liye use hoti hai. Ek assembly mein ek ya zyada types (classes, interfaces, structures, etc.) hoti hain, aur yeh .NET framework ka fundamental unit hoti hai.

Types of Assemblies:

  1. Private Assemblies:

    • Yeh ek hi application ke liye hoti hain.

    • Yeh application ke directory ya subdirectory mein store hoti hain.

  2. Shared Assemblies:

    • Yeh multiple applications ke liye hoti hain.

    • Yeh Global Assembly Cache (GAC) mein store hoti hain.

  3. Dynamic Assemblies:

    • Yeh runtime par create hoti hain, usually System.Reflection.Emit namespace ka use karke.

    • Yeh AppDomain mein load ki ja sakti hain bina pre-compiled hone ke.

Global Assembly Cache (GAC):

GAC ek central repository hota hai jahan shared assemblies rakhi jaati hain jo multiple applications ke dwara use hoti hain. Assemblies GAC mein unke strong name ke basis par store hoti hain, jo assembly ka name, version, culture, aur public key include karta hai.

Assemblies ko GAC mein install kaise karein:

  • gacutil tool ka use karke ya drag and drop karke assembly ko GAC folder (C:\Windows\Assembly) mein dal sakte hain.


Threads in C#

Thread ek process ka smallest unit hota hai jo execute hota hai. .NET mein threads System.Threading namespace ka part hote hain.

Creating and Managing Threads:

  1. Thread Creation:

    • Aap Thread class ka use karke thread create kar sakte hain aur Thread.Start() method se start kar sakte hain.

    Thread myThread = new Thread(new ThreadStart(MyMethod));
    myThread.Start();
  2. Thread State:

    • Thread kai states se guzar sakta hai: Unstarted, Running, WaitSleepJoin, Stopped, etc.

  3. Thread Lifecycle:

    • Ek baar thread start hone ke baad, jo method diya gaya hota hai, vo execute hota hai aur phir terminate ho jaata hai.

Thread Pooling:

Thread Pool ek collection hota hai worker threads ka. Har baar naya thread create karne ki jagah, aap pool se threads reuse kar sakte hain.

  • Advantages: Thread create karne aur destroy karne ka overhead kam hota hai.

  • ThreadPool.QueueUserWorkItem() se task ko queue kar sakte hain.

    ThreadPool.QueueUserWorkItem(WorkerMethod);

Thread Contexts and Concurrency

Contexts:

Ek Thread Context ek thread ke execution environment ko represent karta hai, jisme execution stack, CPU state, aur registers aati hain.

Concurrency:

Concurrency ka matlab hota hai jab multiple threads ek hi time period mein progress karte hain. Thread synchronization zaroori hoti hai taaki data consistency banaye rakhein aur race conditions jaise issues se bacha ja sake.

Synchronization:

Jab multiple threads shared resources ko access karte hain, to synchronization zaroori hoti hai taaki data corruption ya inconsistent results se bacha ja sake. C# mein kaafi synchronization mechanisms available hain:

  1. Locks (Monitor):

    • lock ek C# keyword hai jo Monitor class ka use simplify karta hai.

    • Yeh ensure karta hai ki ek waqt mein sirf ek thread critical section mein enter kar sake.

    lock(myLockObject)
    {
        // Critical section
    }
  2. Monitor:

    • Monitor aapko Enter aur Exit methods provide karta hai lock acquire aur release karne ke liye.

    Monitor.Enter(myLockObject);
    try
    {
        // Critical section
    }
    finally
    {
        Monitor.Exit(myLockObject);
    }
  3. Reader-Writer Lock:

    • Ek ReaderWriterLock multiple threads ko shared resource ko read karne ka permission deta hai, lekin writing ke liye exclusive access ki zaroorat hoti hai.

    ReaderWriterLock rwLock = new ReaderWriterLock();
    rwLock.AcquireReaderLock(Timeout.Infinite);
    rwLock.ReleaseReaderLock();
  4. Mutex:

    • Ek Mutex ek system-wide synchronization object hota hai. Yeh threads ko different processes mein synchronize karne ke liye use hota hai.

    Mutex mutex = new Mutex();
    mutex.WaitOne(); // Acquire
    mutex.ReleaseMutex(); // Release

AppDomains

Ek AppDomain ek isolation mechanism hota hai jo .NET runtime mein applications ko isolate karta hai. Har application apne AppDomain mein run hoti hai, jo execution, security, aur configuration ka boundary provide karta hai.

AppDomains kyun use karein?

  1. Isolation: AppDomains ensure karte hain ki ek application doosre ko affect na kare (e.g., memory corruption se bachna).

  2. Security: AppDomains security policies ka boundary provide karte hain.

  3. Loading and Unloading Assemblies: Assemblies ko dynamically load ya unload kiya ja sakta hai ek AppDomain mein.

Creating and Managing AppDomains:

  • Aap AppDomain.CreateDomain() aur AppDomain.Unload() methods ka use karke AppDomains create aur unload kar sakte hain.

    AppDomain newDomain = AppDomain.CreateDomain("NewDomain");
    AppDomain.Unload(newDomain);

Processes in C#

Process ek running application ka instance hota hai. Ek process ke andar ek ya zyada threads hote hain.

Process Class:

System.Diagnostics.Process class ka use karke aap processes ke saath interact kar sakte hain.

  • Starting a Process:

    Process.Start("notepad.exe");
  • Getting Process Information:

    Process proc = Process.GetProcessesByName("notepad")[0];
    Console.WriteLine(proc.MainWindowTitle);

Concurrency and Synchronization

Concurrency ka matlab hota hai jab multiple threads simultaneously run kar rahe hote hain aur shared resources access kar rahe hote hain. Aapko ensure karna padta hai ki operations thread-safe ho taaki race conditions ya deadlocks se bacha ja sake.

Common Synchronization Mechanisms:

  1. Locks:

    • Locks ka use ensure karne ke liye ki ek waqt mein sirf ek thread hi resource access kare.

  2. Monitors:

    • Monitors aapko critical sections mein threads ko enter aur exit karne ki control deta hai. lock keyword isse simplify karta hai.

  3. ReaderWriterLock:

    • Yeh multiple threads ko read access deta hai, lekin writing ke liye exclusive access chahiye hota hai.

  4. Mutex:

    • Mutex ka use synchronization ke liye hota hai across different processes.

  5. Semaphore:

    • Semaphore ek synchronization object hota hai jo resource access ko limit karta hai, jisme ek defined number of threads resource ko concurrently access kar sakte hain.


Summary

Yeh unit C# mein threads, app domains, aur assemblies ko manage karne par focus karta hai. Isse aap concurrency, synchronization, aur processes ko samajhte hain jo aapko .NET applications mein required hoti hain. Synchronization tools jaise locks, monitors, reader-writer locks, mutexes, aur semaphores ki madad se aap data consistency ko maintain kar sakte hain. AppDomains applications ko isolate karte hain aur security policies ko implement karte hain.

PreviousUnit - II (English Version - for papers)NextUnit - III ( English - Version )

Last updated 4 months ago