473,406 Members | 2,439 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,406 software developers and data experts.

Weird Invoke problem

msjonathan
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).
Expand|Select|Wrap|Line Numbers
  1. if (InvokeRequired)
  2.             this.Invoke((MethodInvoker)delegate { Application.Exit(); });
  3.          else
  4.             Application.Exit();
  5.  
When I changed the code to:
Expand|Select|Wrap|Line Numbers
  1. MethodInvoker toExecute = delegate
  2.          {
  3.             Application.Exit();
  4.          };
  5.  
  6.          if (InvokeRequired)
  7.             this.Invoke(toExecute);
  8.          else
  9.             Application.Exit();
  10.  
It worked, Does anybody know what's the difference between those pieces of code? It looks almost the same.

Greetz,

Jonatahn
Jun 8 '10 #1
7 1742
Christian Binder
218 Expert 100+
@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?
Jun 9 '10 #2
@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
Jun 9 '10 #3
Christian Binder
218 Expert 100+
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 ...
Jun 9 '10 #4
I am running 3.5 also, will try with a messagebox.show()

maybe I have to post a little bit of code:

Expand|Select|Wrap|Line Numbers
  1. try{
  2. if (DateTime.Now.Date > LicenseSettings.MaxDate || DateTime.Now.Date > GalantisSettings.LockDate)
  3.                throw new ArgumentException("Expired!");
  4.  
  5. ...
  6. }catch (ArgumentException)
  7.          {
  8.             #region Galantis is expired
  9.             ShowMessageBox(Translation.Translate(TranslationKeys.GalantisExpired, TranslationFormat.Standard), MessageBoxIcon.Stop);
  10.             ExitApplication();
  11.             #endregion
  12.          }
  13. Finally
  14. {
  15.  TimeSpan tsLicense = new TimeSpan(GalantisSettings.LOCKOUT_DAYS + 1, 0, 0, 0);
  16.             TimeSpan tsGalantis = new TimeSpan(GalantisSettings.LOCKOUT_DAYS + 1, 0, 0, 0);
  17.  
  18.             if (LicenseSettings != null)
  19.                tsLicense = LicenseSettings.MaxDate.Subtract(DateTime.Now.Date);
  20.  
  21.             if (GalantisSettings != null)
  22.                tsGalantis = GalantisSettings.LockDate.Subtract(DateTime.Now.Date);
  23.  
  24.             if (tsLicense.TotalDays > 0 && tsGalantis.TotalDays > 0)
  25.                if (tsLicense.TotalDays <= GalantisSettings.LOCKOUT_DAYS || tsGalantis.TotalDays <= GalantisSettings.LOCKOUT_DAYS)
  26.                   ShowMessageBox(Translation.Translate(TranslationKeys.GalantisLockedDown, Math.Min(tsLicense.TotalDays, tsGalantis.TotalDays).ToString(), TranslationFormat.Standard), MessageBoxIcon.Warning);
  27. }
  28.  
  29. private void ExitApplication()
  30.       {
  31.  
  32.          MethodInvoker toExecute = delegate
  33.          {
  34.             Application.Exit();
  35.          };
  36.  
  37.          if (InvokeRequired)
  38.             this.Invoke(toExecute);
  39.          else
  40.             Application.Exit();
  41.       }
  42.  
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
Jun 9 '10 #5
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
Expand|Select|Wrap|Line Numbers
  1. # if (tsLicense.TotalDays > 0 && tsGalantis.TotalDays > 0)
  2. #                if (tsLicense.TotalDays <= GalantisSettings.LOCKOUT_DAYS || tsGalantis.TotalDays <= GalantisSettings.LOCKOUT_DAYS)
  3. #                   ShowMessageBox(Translation.Translate(TranslationKeys.GalantisLockedDown, Math.Min(tsLicense.TotalDays, tsGalantis.TotalDays).ToString(), TranslationFormat.Standard), MessageBoxIcon.Warning);
  4.  
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
Jun 9 '10 #6
Christian Binder
218 Expert 100+
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.
Jun 9 '10 #7
ok, thanks for your help will look into it some further.
Jun 9 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

6
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...
2
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....
11
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...
1
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...
1
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...
2
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...
0
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;
6
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...
6
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:...
16
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") ...
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?
1
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
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...
0
agi2029
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,...
0
isladogs
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...

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.