Tural Suleymani
Managed and Unmanaged Resources in .NET

What are managed and unmanaged resources? Which built-in method and interface we have for unmanaged resources?

By Tural Suleymani in .NET on Jul 19 2022
  • Rajanikant Hawaldar
    Oct, 2022 13

    Managed resources are those that are pure.NET code and managed by the runtime and are under its direct control. Unmanaged resources are those that are not. File handles, pinned memory, COM objects, database connections etc
    // using unmanaged code

    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Data;
    5. using System.Drawing;
    6. using System.Linq;
    7. using System.Text;
    8. using System.Threading.Tasks;
    9. using System.Windows.Forms;
    10. using System.Runtime.InteropServices;
    11. namespace DllImportSample
    12. {
    13. public partial class frmDllImportSample : Form
    14. {
    15. [DllImport("user32.dll")]
    16. private static extern int MessageBox(IntPtr hWnd, String lpText, String lpCaption, uint uType);
    17. public frmDllImportSample()
    18. {
    19. InitializeComponent();
    20. }
    21. private void btnMessageBox_Click(object sender, EventArgs e)
    22. {
    23. MessageBox(new IntPtr(this.Handle.Int32()), @"Calling MessageBox Win32 API from C#", @"MessageBox", 0);
    24. System.Windows.Forms.MessageBox.Show(@"This is C# MessageBox!", @"MessageBox");
    25. }
    26. }
    27. }

    • 1


Most Popular Job Functions


MOST LIKED QUESTIONS