Friday, 29 July 2016

only one time user will login in C# winform Application

namespace TestWinApp
{
    public partial class Form1 : Form
    {
        public static int count = 0;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {          
            bool result;
            var mutex = new System.Threading.Mutex(true, "UniqueAppId", out result);

            if (!result)
            {
                MessageBox.Show("Another user is already running.");
                return;
            }
            //Application.Run(new Form1());
            GC.KeepAlive(mutex);          
        }    
    }
}

No comments:

Post a Comment