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.

in between System.Diagnostics.Process.GetProcesses method is not
available in embedded VB, so any other alternative to resolve this..

Cheers
Sid

Re: How To Avoid Multiple Instances by ---

---
Wed Mar 26 08:10:21 PDT 2008

On Wed, 26 Mar 2008 05:02:13 -0700 (PDT), sid <mailsid@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

Re: How To Avoid Multiple Instances by sid

sid
Wed Mar 26 08:24:26 PDT 2008

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. =A0But the Fi=
ndWindow
> 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 eithe=
r
> instance has created its window. =A0I 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.

Re: How To Avoid Multiple Instances by James

James
Wed Mar 26 10:31:23 PDT 2008

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.


Re: How To Avoid Multiple Instances by sid

sid
Wed Mar 26 10:48:42 PDT 2008

On 26 Mar, 17:31, "James" <james_dev...@hotmail.comi> wrote:
> Is there not a way inside the main function to see if a class has already
> been instantiated?
>
> "sid" <mail...@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.- Hide quoted text -
>
> - Show quoted text -

the problem is with this .NET compact framework due to reduced number
of methods available

i am just not able to find the right collection/ choice of methods
that will solve the problem...on desktops we can get the list of
processes running and then take actions appropriately....

sid

Re: How To Avoid Multiple Instances by Chris

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.
>



Re: How To Avoid Multiple Instances by r_z_aret

r_z_aret
Wed Mar 26 12:03:55 PDT 2008

On Wed, 26 Mar 2008 05:02:13 -0700 (PDT), sid <mailsid@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.

I just used google (http://groups.google.com/advanced_group_search) to
look up
single instance evb
and got 13 hits. I took a quick look and found at least one thread
that looks relevant and useful, and is in a newsgroup that is
certainly more relevant than microsoft.public.pocketpc (primarily for
non-programmers), and at least somewhat more relevant than
microsoft.public.pocketpc.developer.


-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret, eMVP
PenFact, Inc.
20 Park Plaza, Suite 478
Boston, MA 02116
www.penfact.com