473,378 Members | 1,426 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Wpf Question: No CloseReason?

Hi,

I'm trying to begin a new application in Wpf, and I'm trying to do
some similar things to what I have been in Wpf.

For example, in WinForms I have a base BusinessEditForm class. This
overrides OnClosing, which checks the CloseReason. If the reason is
anything other than ApplicationExit, I prompt the user if they would
like to save their changes if the business object being edited is
dirty.

I just let the window close if ApplicationExit is the reason, however,
because I only even call that method if a background thread determines
the I have locked out the application and all instances MUST exit
immediately.

I would like similar functionality in Wpf, but I can't figure out any
way to see if the user chose to close the window, or I've started a
shutdown.

Any ideas?

Thanks
Andy
Jun 27 '08 #1
4 5472
On May 5, 8:30 am, Andy <an...@med-associates.comwrote:
Hi,

I'm trying to begin a new application in Wpf, and I'm trying to do
some similar things to what I have been in Wpf.

For example, in WinForms I have a base BusinessEditForm class. This
overrides OnClosing, which checks the CloseReason. If the reason is
anything other than ApplicationExit, I prompt the user if they would
like to save their changes if the business object being edited is
dirty.

I just let the window close if ApplicationExit is the reason, however,
because I only even call that method if a background thread determines
the I have locked out the application and all instances MUST exit
immediately.

I would like similar functionality in Wpf, but I can't figure out any
way to see if the user chose to close the window, or I've started a
shutdown.

Any ideas?

Thanks
Andy
See this post:

http://forums.microsoft.com/MSDN/Sho...56734&SiteID=1

Chris
Jun 27 '08 #2
On May 5, 10:39 am, Chris Dunaway <dunaw...@gmail.comwrote:
See this post:

http://forums.microsoft.com/MSDN/Sho...56734&SiteID=1

Chris
Ugh. Rather ugly for something that should be simple. Thanks.
Jun 27 '08 #3
On Mon, 05 May 2008 07:50:35 -0700, Andy <an***@med-associates.comwrote:
On May 5, 10:39 am, Chris Dunaway <dunaw...@gmail.comwrote:
>See this post:

http://forums.microsoft.com/MSDN/Sho...56734&SiteID=1

Chris

Ugh. Rather ugly for something that should be simple. Thanks.
Well, I'd like to point out that the only need you've stated for this is
an apparent issue of your own code deadlocking. Also, it's debatable as
to whether an application that's deadlocked can be consider it safe to
save user data.

Deadlocking code is itself "rather ugly", so this seems a little bit like
the classic tale of the pot and the kettle. :)

If you really must deal with this sort of scenario, why not just have the
code that would normally call ApplicationExit go ahead and handle the
"save data" logic itself, rather than doing that when you detect that the
window is closing?

Pete
Jun 27 '08 #4
On May 5, 12:58 pm, "Peter Duniho" <NpOeStPe...@nnowslpianmk.com>
wrote:
Well, I'd like to point out that the only need you've stated for this is
an apparent issue of your own code deadlocking. Also, it's debatable as
to whether an application that's deadlocked can be consider it safe to
save user data.
Not a deadlock in the traditional sense, so I can't solve it in the
traditional sense. The problem I was addressing in WinForms was a
need to be able to force users out of my application. The normal flow
of OnClosing for forms in that application would check to see if the
object on the form was dirty and prompting the user to save changes
using a standard MessageBox prompt. Application.Exit would close the
application, but the window closing event could cause this MessageBox
prompt. If the user answers the prompt, the window would continue to
close (after saving, if needed) and everything would be fine. But the
user may not even be at the workstation, and I really need them out to
update the server side code.
If you really must deal with this sort of scenario, why not just have the
code that would normally call ApplicationExit go ahead and handle the
"save data" logic itself, rather than doing that when you detect that the
window is closing?
I should have probably mentioned this is an MDI application, and its
only the MDI children that are checking while they are closing. It
normally terminates when the main MDI parent is closed by the user.
The Application.Exit call would only happen on a special background
thread which checks the database to see if it should shutdown. Maybe
not the best setup, because it relies on me not calling
Application.Exit for any other reason, but I haven't been able to
think of any other good reason to do so because the the user closing
the parent would also terminate the application.

If I should be going another route to get this functionality, that's
fine. On a side note, I'm also hoping this functionality can be put
into a library. With WinForms, I have a class assembly that contains
a Form subclass... but it looks like VS won't let me use anything but
Window for the base class of Wpf forms. Maybe I should be making
everything a user control instead? So much to learn..

Thanks!
andy
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Stevey | last post by:
I have the following XML file... <?xml version="1.0"?> <animals> <animal> <name>Tiger</name> <questions> <question index="0">true</question> <question index="1">true</question> </questions>
7
by: nospam | last post by:
Ok, 3rd or is it the 4th time I have asked this question on Partial Types, so, since it seems to me that Partial Types is still in the design or development stages at Microsoft, I am going to ask...
3
by: Ekqvist Marko | last post by:
Hi, I have one Access database table including questions and answers. Now I need to give answer id automatically to questionID column. But I don't know how it is best (fastest) to do? table...
10
by: glenn | last post by:
I am use to programming in php and the way session and post vars are past from fields on one page through to the post page automatically where I can get to their values easily to write to a...
10
by: Rider | last post by:
Hi, simple(?) question about asp.net configuration.. I've installed ASP.NET 2.0 QuickStart Sample successfully. But, When I'm first start application the follow message shown. ========= Server...
53
by: Jeff | last post by:
In the function below, can size ever be 0 (zero)? char *clc_strdup(const char * CLC_RESTRICT s) { size_t size; char *p; clc_assert_not_null(clc_strdup, s); size = strlen(s) + 1;
56
by: spibou | last post by:
In the statement "a *= expression" is expression assumed to be parenthesized ? For example if I write "a *= b+c" is this the same as "a = a * (b+c)" or "a = a * b+c" ?
2
by: Allan Ebdrup | last post by:
Hi, I'm trying to render a Matrix question in my ASP.Net 2.0 page, A matrix question is a question where you have several options that can all be rated according to several possible ratings (from...
2
by: Academia | last post by:
Protected Overrides Sub OnFormClosing(ByVal e As System.Windows.Forms.FormClosingEventArgs) MyBase.OnFormClosing(e) Console.WriteLine(e.CloseReason.ToString )
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.