PPC single instance

T

Tod Johnson

Hi,

Have noticed that on PPC the application started in the single-instance
mode. I've read that if I change a title of the window with class
"#NETCF_AGL_PARK_" ('_' suffix showed by WindowsCE Remote Spy) then the
application become multi-instance. But as I see it doesn't...

Are any thoughts?

Thanks,
Tod
 
T

Tod Johnson

Thanks Peter, but I read this article, there written that the class name
is #NETCF_AGL_PARK but throuh Remote Spy I noticed that it indeed is
"#NETCF_AGL_PARK_" maybe because of my CF.NET SP2... also this method
doesn't work at all again maybe because of my CF.NET SP2...
 
A

Alex Feinman [MVP]

You are correct - the class name now has the underscore in it. The code
works after this change
string path =
Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;

IntPtr hWnd = Win32Window.FindWindow("#NETCF_AGL_PARK_", path);
 
T

Tod Johnson

It returns the correct hWnd but after changing the text of this window
seems that single instance problem exists.
 
A

Alex Feinman [MVP]

I have actually verified it before posting - I was indeed able to launch the
second instance. Could you perhaps post a code snippet, so that I could see
what is is if anything you are doing differently?

--
Alex Feinman
---
Visit http://www.opennetcf.org
Tod Johnson said:
It returns the correct hWnd but after changing the text of this window
seems that single instance problem exists.
You are correct - the class name now has the underscore in it. The code
works after this change
string path =
Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;
IntPtr hWnd = Win32Window.FindWindow("#NETCF_AGL_PARK_", path);
 
T

Tod Johnson

Sorry, I didn't want to be rude. Here is a code snippet:

the idea is -- the program code can execute itself and pass ProcessID to
be terminated.

static void Main(string [] argv)
{
if (argv.Length > 0)
{
MessageBox.Show("Test");
TerminateProcess(Convert.ToUInt32(argv[0]));
return;
}

Application.Run(new MainForm());
OpenNETCF.Diagnostics.Process.Start(
ISS.CF.Library.Utils.AppPath(), CurrentProcessID.ToString());

}


public class MainForm : Form
{
...
OnLoad()
{
string path =
Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;
IntPtr hWnd = Win32Window.FindWindow("#NETCF_AGL_PARK_", path);
SetWindowText(hWnd, Path.Combine(Path.GetDirectory(path), "test.exe"));
}

[DllImport("coredll")]
public static extern int SetWindowText(IntPtr hwnd, string lpString);

}


Thanks for the help,
Tod
 
A

Alex Feinman [MVP]

I'm not sure how is this supposed to work. The code after Application.Run
will not execute until the main form is closed.

--
Alex Feinman
---
Visit http://www.opennetcf.org
Tod Johnson said:
Sorry, I didn't want to be rude. Here is a code snippet:

the idea is -- the program code can execute itself and pass ProcessID to
be terminated.

static void Main(string [] argv)
{
if (argv.Length > 0)
{
MessageBox.Show("Test");
TerminateProcess(Convert.ToUInt32(argv[0]));
return;
}

Application.Run(new MainForm());
OpenNETCF.Diagnostics.Process.Start(
ISS.CF.Library.Utils.AppPath(), CurrentProcessID.ToString());

}


public class MainForm : Form
{
...
OnLoad()
{
string path =
Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName;
IntPtr hWnd = Win32Window.FindWindow("#NETCF_AGL_PARK_", path);
SetWindowText(hWnd, Path.Combine(Path.GetDirectory(path), "test.exe"));
}

[DllImport("coredll")]
public static extern int SetWindowText(IntPtr hwnd, string lpString);

}


Thanks for the help,
Tod

I have actually verified it before posting - I was indeed able to launch
the second instance. Could you perhaps post a code snippet, so that I
could see what is is if anything you are doing differently?
 
T

Tod Johnson

Yes, you are right in the certain condition the main form become closed
and at this moment started another application.

To tell the truth I'd like to terminate application itself when it
hanging... I've noticed that it hanging even if the application
terminated when thread trying to receive data from a Socket.

That's why I decided to terminate my application after the closing main
form to ensure that it is really terminated.
 

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