Hej hej,
I had something very weird when I had to close our application. It came in our method with this code.
(the invoke code was hit, but did not close our application). -
if (InvokeRequired)
-
this.Invoke((MethodInvoker)delegate { Application.Exit(); });
-
else
-
Application.Exit();
-
When I changed the code to: -
MethodInvoker toExecute = delegate
-
{
-
Application.Exit();
-
};
-
-
if (InvokeRequired)
-
this.Invoke(toExecute);
-
else
-
Application.Exit();
-
It worked, Does anybody know what's the difference between those pieces of code? It looks almost the same.
Greetz,
Jonatahn
7 1742 @msjonathan
I've tried this and both of your codes did work. Maybe there's another problem which lets your code fail.
Did you tried the non-working code more than once?
What's happening? Are there any error-messages or is does your program just don't do anything?
@ChBinder
yes I did it like 10 times, there is not error and I am running with my debug exceptions on so I should notice if there is any error.
When we do the first piece code the program just continues and does not exit. But when we do the second piece of code the program exits perfectly. It's a very weird problem because I think those 2 pieces of code should do exactly the same.
Greetz
Jonathan
Yes, I think so too.
Which framework do you use? I've tried it within 3.5 but I can hardly think that this would be the cause of your error.
You could try other things han Application.Exit(), e.g. show a MessageBox. This is really a very weird thing ...
I am running 3.5 also, will try with a messagebox.show()
maybe I have to post a little bit of code: -
try{
-
if (DateTime.Now.Date > LicenseSettings.MaxDate || DateTime.Now.Date > GalantisSettings.LockDate)
-
throw new ArgumentException("Expired!");
-
-
...
-
}catch (ArgumentException)
-
{
-
#region Galantis is expired
-
ShowMessageBox(Translation.Translate(TranslationKeys.GalantisExpired, TranslationFormat.Standard), MessageBoxIcon.Stop);
-
ExitApplication();
-
#endregion
-
}
-
Finally
-
{
-
TimeSpan tsLicense = new TimeSpan(GalantisSettings.LOCKOUT_DAYS + 1, 0, 0, 0);
-
TimeSpan tsGalantis = new TimeSpan(GalantisSettings.LOCKOUT_DAYS + 1, 0, 0, 0);
-
-
if (LicenseSettings != null)
-
tsLicense = LicenseSettings.MaxDate.Subtract(DateTime.Now.Date);
-
-
if (GalantisSettings != null)
-
tsGalantis = GalantisSettings.LockDate.Subtract(DateTime.Now.Date);
-
-
if (tsLicense.TotalDays > 0 && tsGalantis.TotalDays > 0)
-
if (tsLicense.TotalDays <= GalantisSettings.LOCKOUT_DAYS || tsGalantis.TotalDays <= GalantisSettings.LOCKOUT_DAYS)
-
ShowMessageBox(Translation.Translate(TranslationKeys.GalantisLockedDown, Math.Min(tsLicense.TotalDays, tsGalantis.TotalDays).ToString(), TranslationFormat.Standard), MessageBoxIcon.Warning);
-
}
-
-
private void ExitApplication()
-
{
-
-
MethodInvoker toExecute = delegate
-
{
-
Application.Exit();
-
};
-
-
if (InvokeRequired)
-
this.Invoke(toExecute);
-
else
-
Application.Exit();
-
}
-
When we break it comes in the exitApplication() method, then we go further it goes into the finally. When we use this lines of code the program quits correct, when we use the old code the program does not quit.
Greetz
Jonathan
I tested it with messagebox.show and it worked, but also Application.Exit() works also, the only thing I changed also was putting in a finally -
# if (tsLicense.TotalDays > 0 && tsGalantis.TotalDays > 0)
-
# if (tsLicense.TotalDays <= GalantisSettings.LOCKOUT_DAYS || tsGalantis.TotalDays <= GalantisSettings.LOCKOUT_DAYS)
-
# ShowMessageBox(Translation.Translate(TranslationKeys.GalantisLockedDown, Math.Min(tsLicense.TotalDays, tsGalantis.TotalDays).ToString(), TranslationFormat.Standard), MessageBoxIcon.Warning);
-
So the messagebox was not called any more, could that be it? when a messagebox is called after a Application.exit() the program does not stop, but keeps running?
Edit: but when I comment my finally so no messagebox is called, the application does not exit either, Can this be a Threading problem?
Greetz,
Jonathan
Yes, maybe there are other Threads running. Application.Exit waits until all Threads are finished. If another Thread is running, the GUI might bei closed, but the program isn't finished completely since all threads are done.
ok, thanks for your help will look into it some further.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brian |
last post by:
Here's the example:
You have a world writable file called lastquote.cfg on your server with a
one or two digit number in it. When you run the script below, it reads the
value, increments the...
|
by: holgeradelmann |
last post by:
Can anyone help please:
I found a nice article on the web how to write my dynamice information into
an RSS-XML.
But I cannot get the code to work.
The problem is so simple but weird....
|
by: neoromance |
last post by:
I ran into a weird memory problem.
my c++ code got a segmentation error at the execution. why I try to
debug it with gdb, I found out it was due to an earlier memory problem.
I then used both...
|
by: Jeffrey Melloy |
last post by:
I recently noticed that in my web app, a \n wasn't getting converted to
a <br />. (The problem turned out to be that for this particular
record, it was a \r).
When I checked out the record in...
|
by: Ot |
last post by:
I have two different solutions that use xml serialization to create xml
from a given class.
The class is defined identically in both solutions. I copied the code for
both the class and the code...
|
by: Matthias S. |
last post by:
I'm using C#Express Beta and the framework 2.0.
I recently realized that my application, when starting has a workingset
peak of ~128 MegaB. I startet wondering a bit because the application...
|
by: Zwyatt |
last post by:
having a really weird little bug w/ time_t...check it out:
I have the following code (simplified here):
#include <time.h>
class A
{
public:
char *aString;
int aNum;
|
by: Boni |
last post by:
Dear sirs/madam,
I am trying to dynamically invoke assembly. (For some days Tomas helped me
to get it compiled). Now I am so far that I can test if the assembly
invoked. And I get the...
|
by: kwest |
last post by:
I just setup a new server with PHP 5 and ran into a problem with
includes. Everytime I call something like
require_once './includes/test.inc'
I get a permissions message like this:
Warning:...
|
by: Bill Nguyen |
last post by:
I'm running into a very weird problem regarding subtraction.
Subtraction behaves as if it's an addition in the below sub
txtJacoCost.Text = Format(mRackc - (mDisc + mJaEc), "0.#####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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |