“make single instance application” what does this do?

后端 未结 7 2014
后悔当初
后悔当初 2020-12-19 02:58

in vb 2008 express this option is available under application properties. does anyone know what is its function? does it make it so that it\'s impossible to open two instanc

7条回答
  •  遥遥无期
    2020-12-19 03:44

    There is even a easier method:

    Use the following code...

    Imports System.IO
    

    On the main form load event do the following:

    If File.Exist(Application.StartupPath & "\abc.txt") Then
        'You can change the extension of the file to what ever you desire ex: dll, xyz etc.
        MsgBox("Only one Instance of the application is allowed!!!")
        Environment.Exit(0)
    Else
        File.Create(Application.StartupPath & "\abc.txt", 10, Fileoptions.DeleteonClose)
    Endif
    

    This will take care of single instances as well as thin clients, and the file cannot be deleted while the application is running. and on closing the application or if the application crashes the file will delete itself.

提交回复
热议问题