Detect multiple instances of the application

Detect multiple instances of the application
This Visual Basic .NET code will detect if multiple instances of the current application are running by retrieving the number of running processes with the same name.

  1. ‘If we find two or more running processes by the same name
  2. If 
    Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName).Length > 1 Then
  3.  ' Tell the user he can only have on instance running
  4.     MessageBox.Show("Only one instance of this program can be open at a given time""Duplicate instance detected", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
  5.  ' Close the application
  6.     Application.Exit()
  7. End If
Nathan Pakovskie is an esteemed senior developer and educator in the tech community, best known for his contributions to With a passion for coding and a knack for simplifying complex tech concepts, Nathan has authored several popular tutorials on C# programming, ranging from basic operations to advanced coding techniques. His articles, often characterized by clarity and precision, serve as invaluable resources for both novice and experienced programmers. Beyond his technical expertise, Nathan is an advocate for continuous learning and enjoys exploring emerging technologies in AI and software development. When he’s not coding or writing, Nathan engages in mentoring upcoming developers, emphasizing the importance of both technical skills and creative problem-solving in the ever-evolving world of technology. Specialties: C# Programming, Technical Writing, Software Development, AI Technologies, Educational Outreach

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top