running applications twice

G

Guest

hi i have developed a pocket pc apps in vb.net vs 2003
for mobile 2003 and mobile 2005 editions

my problem is the user sometimes click the program Icon twice or thrice,
then the programm apps is running twice or thrice, which is not suggestable.
i want to stop multiple same program.

could pls help me to stop click twice or thrice for that program not to run.
how can i do it.
for mobile 2003, mobile 2005,
pls give the code in vb.net 2003


I want to check memory if any of the applications are running, and if so
 
A

archparag

Hi rt,
I was also facing same problem. Here I can suggest you
something, however it do not check the memory, but may be useful if you
wanna try it out to avoid multiple instances of same application. You
can hide the main form while showing any other forms (ie. try keeping
one single form visible at a time, if you need any input then try out
ShowDialogue() instead of Show() ). Also, try changing the text
property of all the forms to be the same. Does your Main form have
MinimizeBox property set to True or False ?

Regards,
Bipin Kesharwani
(Developer)

Palewar Techno Solutions
Pocket PC & Mobile Software Development
Nagpur, India

http://www.palewar.com
 
G

Guest

hi archparag,

anyother way... pls

thanks


Hi rt,
I was also facing same problem. Here I can suggest you
something, however it do not check the memory, but may be useful if you
wanna try it out to avoid multiple instances of same application. You
can hide the main form while showing any other forms (ie. try keeping
one single form visible at a time, if you need any input then try out
ShowDialogue() instead of Show() ). Also, try changing the text
property of all the forms to be the same. Does your Main form have
MinimizeBox property set to True or False ?

Regards,
Bipin Kesharwani
(Developer)

Palewar Techno Solutions
Pocket PC & Mobile Software Development
Nagpur, India

http://www.palewar.com
 
B

Brooke

Here is how I do it in native C/C++ using the Win32 API. You could use
interop and place the code in the main function before Application.Run().

// Only allow one instance of the application
// Check to see if program is already running
HWND hWnd = FindWindow(szWinName, NULL);

// If the program is already running then make it active and
if(hWnd)
{
SetForegroundWindow((HWND)(((DWORD)hWnd) | 0x01));
return -1;
}
 
G

Guest

hi brooke,

i dont know how to wrice c/c++ code
kindly help in vb.net 2003, to call this
or anyother way?

thanks
 
G

Guest

Hi rt,

The following class can be used to check if an instance of an application is
already running.

Imports System
Imports System.Runtime.InteropServices

Public Class OneInstance

Private Const ERROR_ALREADY_EXISTS As Integer = 183

<DllImport("CoreDll.Dll")> _
Private Shared Function GetLastError() As Integer
End Function
<DllImport("CoreDll.Dll", EntryPoint:="CreateMutexW")> _
Private Shared Function CreateMutex(ByVal lpMutexAttributes As IntPtr,
ByVal InitialOwner As Boolean, ByVal MutexName As String) As Integer
End Function

Public Function IsInstanceRunning() As Boolean
Dim applicationName As String =
System.Reflection.Assembly.GetExecutingAssembly().GetName().Name

If CreateMutex(IntPtr.Zero, True, applicationName) <> 0 Then
Return GetLastError() = ERROR_ALREADY_EXISTS
End If

Return False

End Function

End Class


Harshana Liyanage
Software Architect

Zone24x7
http://www.zone24x7.com
 
G

Guest

hi harshana,

i call this function in main form
everytime it is showing false

if multiple instances it has to show true,
but it is not showing true.
if true i want to end this program.

iam calling like this
i copied a code and placed in a class file

dim a as new OneInstance

if a. IsInstanceRunning() then
end
end if


whats wrong??

thanks


i try to call this
 
G

Guest

Since this is a CompactFramework group, I'll post the semi-working version
exactly as it runs under WindowsMobile5

This works fine if you launch and then later try to launch the app again -
it faithfully brings your previous launch to the front. However, there is
STILL a problem - if, while in the file explorer, you tap the app name 3 or 4
times quickly, you'll still get multiple instances of the app. Does anyone
have ANY idea how to prevent this?


static class Program
{
[DllImport("coredll.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);

[DllImport("coredll.dll", SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

/// <summary>
/// The main entry point for the application.
/// </summary>

[MTAThread]
static void Main()
{
int hWnd = (int) FindWindow("MyApplication", null);
if(hWnd != 0){
SetForegroundWindow((IntPtr)(hWnd | 0x01));
return;
}

IntroScreen.mMain = new IntroScreen();
Application.Run(IntroScreen.mMain);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top