Chris
Wed Mar 26 12:03:45 PDT 2008
Yes, as Robert pointed out, it's called a named mutex. The app should
create one at startup, see if it created or just opened an existing, and
exit out if it opened an existing mutex. It gets a little more complex if
you want the second instance to close and bring the existing instance to the
fore - I usually do that with a worker thread looking for a custom
"activate" event that the second instance sets before shutting itself down.
--
Chris Tacke, Embedded MVP
OpenNETCF Consulting
Giving back to the embedded community
http://community.OpenNETCF.com
"James" <james_devitt@hotmail.comi> wrote in message
news:7F3638C4-862E-4C95-8DF7-8C6AE08ED720@microsoft.com...
> Is there not a way inside the main function to see if a class has already
> been instantiated?
>
>
> "sid" <mailsid@gmail.com> wrote in message
> news:f515ade4-6aac-4a1e-aaec-fc82f0130420@u10g2000prn.googlegroups.com...
>> On 26 Mar, 14:10, ---@--- (Robert Scott) wrote:
>>> On Wed, 26 Mar 2008 05:02:13 -0700 (PDT), sid <mail...@gmail.com> wrote:
>>> >Hi
>>>
>>> >I am writing a windows mobile application using embedded VB.
>>>
>>> >Can anyone suggest a way to avoid "multiple instances" of the
>>> >application.
>>>
>>> >On reading on web they emphasise the usage of SetForeGroundWindow and
>>> >FindWindow API's. But i think if somehow I can manage to get the list
>>> >of currently running processes on the device, I should be able to stop
>>> >execution of second instance.
>>>
>>> But that is more complicated than the FindWindow API, so why bother?
>>>
>>> The only absolutely foolproof method involves a named mutex. But the
>>> FindWindow
>>> method is also reliable, except for the scenario where two instances
>>> might be
>>> started in a short span of time, so that each instance starts before
>>> either
>>> instance has created its window. I use FindWindow in my application and
>>> no one
>>> has ever complained.
>>>
>>> Robert Scott
>>> Ypsilanti, Michigan
>>
>> Thanks for that.
>>
>> The problem is of short-span clicks only.
>>
>> For example a person clicking the application icon 3-4 times in a span
>> of few milliseconds which is likely to happen in my case.
>