Click here to Skip to main content
15,899,679 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: How does Application.DoEvents work? Pin
Luc Pattyn8-Sep-10 2:45
sitebuilderLuc Pattyn8-Sep-10 2:45 
GeneralRe: How does Application.DoEvents work? Pin
Spectre_0018-Sep-10 4:18
Spectre_0018-Sep-10 4:18 
GeneralRe: How does Application.DoEvents work? Pin
Luc Pattyn8-Sep-10 4:30
sitebuilderLuc Pattyn8-Sep-10 4:30 
AnswerRe: How does Application.DoEvents work? Pin
Guy Harwood8-Sep-10 2:05
Guy Harwood8-Sep-10 2:05 
GeneralRe: How does Application.DoEvents work? Pin
Mike Devenney8-Sep-10 2:49
Mike Devenney8-Sep-10 2:49 
AnswerRe: How does Application.DoEvents work? Pin
Patrick Fox8-Sep-10 5:41
Patrick Fox8-Sep-10 5:41 
AnswerRe: How does Application.DoEvents work? Pin
Fabio Franco8-Sep-10 6:15
professionalFabio Franco8-Sep-10 6:15 
GeneralRe: How does Application.DoEvents work? [modified] Pin
the Kris8-Sep-10 8:29
the Kris8-Sep-10 8:29 
That is not correct. The Windows Message queue is not "on" the stack. No weird call stack operations are performed.
For .Net Application.Run() and Application.DoEvents() are somewhat similar in that they both call a message pump. A message pump could be very simply be:
MessagePump()
{
   while ( true )
   {
      Message msg = GetMessage();  // Get the next message from the queue
      DispatchMessage( msg );  // This will do the work
      if ( msg.Msg == WM_QUIT ) break;
   }
}


The code behind DispatchMessage will eventually call your events, e.g. when a button is clicked.
If you then do a form.ShowDialog() it will re-enter the message pump function (recursively, the previous call just stays on the call stack).

This is why showing a message box in a timer event handler will result in stacking up message boxes until resources are exhausted or a stack overflow occurs.

The call stack will look something like this (looking at it top-down) :

Application.Run
MessagePump
DispatchMessage
... framework stuff ...
Timer1.TimerEvent
SomeForm.ShowDialog
Application.DoEvents
MessagePump
DispatchMessage
... framework stuff ...
Timer1.TimerEvent
SomeForm.ShowDialog   <-- if you indeed do this call then this will repeat until...


modified on Wednesday, September 8, 2010 2:36 PM

GeneralRe: How does Application.DoEvents work? Pin
Fabio Franco8-Sep-10 8:38
professionalFabio Franco8-Sep-10 8:38 
AnswerRe: How does Application.DoEvents work? Pin
englebart8-Sep-10 8:46
professionalenglebart8-Sep-10 8:46 
AnswerRe: How does Application.DoEvents work? Pin
Scott Barbour8-Sep-10 10:08
Scott Barbour8-Sep-10 10:08 
GeneralRe: How does Application.DoEvents work? Pin
MicroVirus10-Sep-10 12:41
MicroVirus10-Sep-10 12:41 
QuestionCalendarExtender popup appearing when Enter key is pressed Pin
dev_asp_shreshtha6-Sep-10 1:09
dev_asp_shreshtha6-Sep-10 1:09 
AnswerRe: CalendarExtender popup appearing when Enter key is pressed Pin
Pete O'Hanlon6-Sep-10 1:30
mvePete O'Hanlon6-Sep-10 1:30 
QuestionNot able to delete original jpeg file after it is copied with System.IO.File.Copy() Pin
Aseem Sharma5-Sep-10 6:43
Aseem Sharma5-Sep-10 6:43 
AnswerCross post/re-post Pin
Not Active5-Sep-10 7:14
mentorNot Active5-Sep-10 7:14 
QuestionLoad image problem Pin
Mehdi Ghiasi3-Sep-10 5:05
Mehdi Ghiasi3-Sep-10 5:05 
AnswerRe: Load image problem Pin
Dave Kreskowiak3-Sep-10 6:29
mveDave Kreskowiak3-Sep-10 6:29 
AnswerRe: Load image problem Pin
Luc Pattyn3-Sep-10 6:48
sitebuilderLuc Pattyn3-Sep-10 6:48 
QuestionRe: Load image problem [modified] Pin
Mehdi Ghiasi3-Sep-10 15:09
Mehdi Ghiasi3-Sep-10 15:09 
AnswerRe: Load image problem Pin
Dave Kreskowiak3-Sep-10 18:17
mveDave Kreskowiak3-Sep-10 18:17 
QuestionHow to deploy an application along with .net framework Pin
NarVish3-Sep-10 2:13
NarVish3-Sep-10 2:13 
AnswerRe: How to deploy an application along with .net framework Pin
Not Active3-Sep-10 2:22
mentorNot Active3-Sep-10 2:22 
GeneralRe: How to deploy an application along with .net framework Pin
NarVish3-Sep-10 3:16
NarVish3-Sep-10 3:16 
GeneralRe: How to deploy an application along with .net framework Pin
Not Active3-Sep-10 4:05
mentorNot Active3-Sep-10 4:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.