Advertisement
Konark

Untitled

Dec 3rd, 2015
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  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.  
  11. namespace WindowsFormsApplication6
  12. {
  13.     public partial class Form1 : Form
  14.     {
  15.         public class ConfigurationManager
  16.         {
  17.             private static ConfigurationManager configManager;
  18.  
  19.             private ConfigurationManager()
  20.             {
  21.             }
  22.  
  23.             public static ConfigurationManager GetInstance()
  24.             {
  25.                 // для исключения возможности создания двух объектов
  26.                 // при многопоточном приложении
  27.                 if (configManager == null)
  28.                 {
  29.                     lock (typeof(ConfigurationManager))
  30.                     {
  31.                         if (configManager == null)
  32.                             configManager = new ConfigurationManager();
  33.                     }
  34.                 }
  35.  
  36.                 return configManager;
  37.             }
  38.         }
  39.         public Form1()
  40.         {
  41.             InitializeComponent();
  42.         }
  43.  
  44.         private void button1_Click(object sender, EventArgs e)
  45.         {
  46.             ConfigurationManager cfgManager1 = ConfigurationManager.GetInstance();
  47.             ConfigurationManager cfgManager2 = ConfigurationManager.GetInstance();
  48.             if (Object.ReferenceEquals(cfgManager1, cfgManager2))
  49.                 MessageBox.Show(this, "Обе ссылки ссылаются на один объект");
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement