I'm currently designing a VB.NET application for a Smartphone. The
Smartphone itself will prevent you from starting multiple instances of the
same application. Which is true only if your application is fully loaded in
memory. By clicking on the application icon repeatedly multiple instances of
the application will be started and they will run until you close them.
I tried to use Named Mutex and FindWindow but nothing works. I can still
start multiple instances of the same VB.NET application. How can I prevent
multiple instances in a VB.NET application running on a Smarthpone?
One more question, is it normal that an empty application takes up to 3
seconds to start?
--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
"Sylvain Fortin" <Sylvai...@discussions.microsoft.com> wrote in message
news:595B3013-673B-432A...@microsoft.com...
I know it doesn't make any sense and to answer your question I'm using the
example everyone is talking about on this forum:
http://www.gotdotnet.com/userfiles/jonwells/OneInstance.zip
And the following code has been added to my application:
Private oOneInstance AS OneInstance = Nothing
...
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
oOneInstance = New OneInstance(Me)
End Sub
Thanks for your time Chris.
Sylvain Fortin
The larger your application becomes, the longer it takes to load it (simply
load into memory and JIT - I'm not talking about your .NET code), making
this window also larger. The only way around it I can think of is to use a
small and efficient launcher, which would check for your app to be already
running by enumerating the precesses
--
Alex Feinman
---
Visit http://www.opennetcf.org
"Sylvain Fortin" <Sylvai...@discussions.microsoft.com> wrote in message
news:595B3013-673B-432A...@microsoft.com...
That's exactly what I thought, but if you read my first post, you'll see
that I'm asking if it's normal for an empty application (single form, no
menu, etc.) to take up to 3 seconds to load.
With that kind of load time on a .NET application startup, there's no way to
do anything about my multiple instance problem. But there's maybe a work
around. Can I build that small and efficient launcher application using
embedded Microsoft Visual C++ 4 and count the number of processes running in
this application?
Thanks for your time Alex.
Sylvain Fortin
--
Alex Feinman
---
Visit http://www.opennetcf.org
"Sylvain Fortin" <Sylvai...@discussions.microsoft.com> wrote in message
news:022CE056-1CAC-48D2...@microsoft.com...
-Chris
"Alex Feinman [MVP]" <publi...@alexfeinman.com> wrote in message
news:uBsNEByN...@TK2MSFTNGP15.phx.gbl...
and try to repeat this problem on this example:
http://www.sergeybogdanov.com/Samples/SPSingleInstance.zip
Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
Sergey, I already tried the SPSingleInstance.zip example and I'm still able
to run multiple instances of my application. I agree with all of you guys
about “named mutex”, it's not the first time I'm using this technique to
insure I only have one instance of my application but this time it’s not
working and it doesn’t make any sense.
Alex, The device is a Motorola MPx220 and starting the calendar takes less
than 1 second. Most of the applications on the Smartphone have a load time of
less than 1 second.
Thanks for your time everyone, I really appreciate it.
Sylvain Fortin
-Chris
"Sylvain Fortin" <Sylvai...@discussions.microsoft.com> wrote in message
news:6F69B3EC-BF91-433A...@microsoft.com...
CreateMutex() always return a different number which looked like a valid
handle... But I verified the return value of GetLastError() and it returns 6
(ERROR_INVALID_HANDLE) at every call. Any idea?
Thanks for you time.
Sylvain Fortin
if(CreateMutex("MutexName") == true)
{
if(GetLastError == ERROR_ALREADY_EXISTS)
MessageBox("Already Running");
else
MessageBox("First Instance");
}
Make sure your mutex handle's scope is such that it won't get destroyed
until your app closes, where you should call CloseHandle.
--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
"Sylvain Fortin" <Sylvai...@discussions.microsoft.com> wrote in message
news:646C1D11-651B-413F...@microsoft.com...
I wanted to confirm that I'm doing the right thing in a standard windows
application. So I created an empty windows application and I added the
following to test the "named mutex" code:
...
Private Const ERROR_ALREADY_EXISTS As Integer = 183
<DllImport("Kernel32.dll")> _
Private Shared Function GetLastError() As Integer
End Function
<DllImport("Kernel32.dll", EntryPoint:="CreateMutexW")> _
Private Shared Function CreateMutex(ByVal lpMutexAttributes As IntPtr,
ByVal InitialOwner As Boolean, ByVal MutexName As String) As Integer
End Function
Private Sub Form1_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim nResult As Integer
If CreateMutex(IntPtr.Zero, True, "TestMutex") <> 0 Then
nResult = GetLastError()
If (nResult = ERROR_ALREADY_EXISTS) Then
MessageBox.Show(String.Format("Already Running - {0}", nResult))
Else
MessageBox.Show(String.Format("First Instance - {0}", nResult))
End If
End If
End Sub
...
In the standard windows application, everything worked has expected. So I
did the same thing with an empty smartdevice application and I added exactly
the same code except for the DLLImport, changed Kernel32.dll to CoreDLL.dll
to make it work on the smartphone. Same result... It didn't work and
GetLastError() returned 6 (ERROR_INVALID_HANDLE) at every calls. Any idea
what I did wrong?
Thanks for your time Chris.
Regards,
Sylvain Fortin
--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
"Sylvain Fortin" <Sylvai...@discussions.microsoft.com> wrote in message
news:E9ECA0B0-02E4-4A6A...@microsoft.com...
I changed the code like you told me to do and used
Marshal.GetLastWin32Error() instead. Marshal.GetLastWin32Error() always
return 0 and the application still think that CreateMutex() was successful in
creating the mutex (First instance).
Thanks for your time.
Regards,
Sylvain Fortin
Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
"Sergey Bogdanov" <sergey....@gmail.com> wrote in message
news:%239mRkEV...@TK2MSFTNGP14.phx.gbl...
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
"Chris Tacke, eMVP" <cta...@spamfree-opennetcf.org> wrote in message
news:uAo$oOVOFH...@TK2MSFTNGP10.phx.gbl...
I made the following changes after reading your post and it's working now:
<DllImport("CoreDLL.dll", EntryPoint:="CreateMutexW", SetLastError:=True)> _
Private Shared Function CreateMutex(ByVal lpMutexAttributes As IntPtr, ByVal
InitialOwner As Boolean, ByVal MutexName As String) As Integer
End Function
Thanks to everyone who participate to this thread, I really appreciate the
time you spent helping me, everything works now, thanks!
Regards,
Sylvain Fortin
Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
"Sylvain Fortin" <Sylvai...@discussions.microsoft.com> wrote in message
news:329053F6-A05F-46AA...@microsoft.com...
--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
"Daniel Moth" <dmo...@hotmail.com> wrote in message
news:OI5K7XV...@TK2MSFTNGP15.phx.gbl...
--
Chris Tacke
Co-founder
OpenNETCF.org
Has OpenNETCF helped you? Consider donating to support us!
http://www.opennetcf.org/donate
"Sergey Bogdanov" <sergey....@gmail.com> wrote in message
news:%23$dVHeVOF...@TK2MSFTNGP14.phx.gbl...
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
"Sergey Bogdanov" <sergey....@gmail.com> wrote in message
news:%23$dVHeVOF...@TK2MSFTNGP14.phx.gbl...
Best regards,
Sergey Bogdanov
http://www.sergeybogdanov.com
:-)
Cheers
Daniel
--
http://www.danielmoth.com/Blog/
"Chris Tacke, eMVP" <cta...@spamfree-opennetcf.org> wrote in message
news:u1RcksVO...@TK2MSFTNGP10.phx.gbl...
Thanks.