W
wendelborg
The application I'm working on stores all information in-memory due to
security restrictions. One of the problems we are having is other
programs calling SHCloseApps() to free up memory. This will in extreme
cases shut down our application, which effectively means that all
stored information is lost.
To prevent this from happening we have tried to catch the WM_CLOSE
message coming from SHCloseApps. Catching the message works perfectly
through the Application2 class in OpenNETCF. What doesn't work as well
is cancelling the event, as the application exits anyway.
Can anyone tell me if this happens because of the way SHCloseApps
works? Is for instance TerminateProcess called when the application
doesn't close?
The test program is as follows:
----- Program catching WM_CLOSE -----
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[MTAThread]
static void Main()
{
FilterCloseMsg filterCloseMsg = new FilterCloseMsg();
Application2.AddMessageFilter(filterCloseMsg);
Application2.Run(new Form1());
}
}
public class FilterCloseMsg : IMessageFilter
{
private const int WM_CLOSE = 0x0010;
public bool PreFilterMessage(ref Message m)
{
switch (m.Msg)
{
case WM_CLOSE:
{
return true;
}
}
return false;
}
}
------ Method called from another application to free memory -----
[DllImport("aygshell.dll")]
public static extern int SHCloseApps(int dwMemSought);
private void buttonCloseApps_Click(object sender, EventArgs e)
{
SHCloseApps(20 * 1048576); // Test: Try to acquire 20 MB of
memory
}
Hope you can help me.
Best regards,
Tommy Wendelborg
security restrictions. One of the problems we are having is other
programs calling SHCloseApps() to free up memory. This will in extreme
cases shut down our application, which effectively means that all
stored information is lost.
To prevent this from happening we have tried to catch the WM_CLOSE
message coming from SHCloseApps. Catching the message works perfectly
through the Application2 class in OpenNETCF. What doesn't work as well
is cancelling the event, as the application exits anyway.
Can anyone tell me if this happens because of the way SHCloseApps
works? Is for instance TerminateProcess called when the application
doesn't close?
The test program is as follows:
----- Program catching WM_CLOSE -----
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[MTAThread]
static void Main()
{
FilterCloseMsg filterCloseMsg = new FilterCloseMsg();
Application2.AddMessageFilter(filterCloseMsg);
Application2.Run(new Form1());
}
}
public class FilterCloseMsg : IMessageFilter
{
private const int WM_CLOSE = 0x0010;
public bool PreFilterMessage(ref Message m)
{
switch (m.Msg)
{
case WM_CLOSE:
{
return true;
}
}
return false;
}
}
------ Method called from another application to free memory -----
[DllImport("aygshell.dll")]
public static extern int SHCloseApps(int dwMemSought);
private void buttonCloseApps_Click(object sender, EventArgs e)
{
SHCloseApps(20 * 1048576); // Test: Try to acquire 20 MB of
memory
}
Hope you can help me.
Best regards,
Tommy Wendelborg