Click here to Skip to main content
16,005,222 members
Home / Discussions / C#
   

C#

 
Questionconvert WMA , AAC or FLAC to PCM(WAV) in C# Pin
Member 398136629-Sep-08 3:18
Member 398136629-Sep-08 3:18 
AnswerRe: convert WMA , AAC or FLAC to PCM(WAV) in C# Pin
Simon P Stevens29-Sep-08 4:51
Simon P Stevens29-Sep-08 4:51 
AnswerRe: convert WMA , AAC or FLAC to PCM(WAV) in C# Pin
Anthony Mushrow29-Sep-08 5:13
professionalAnthony Mushrow29-Sep-08 5:13 
QuestionVS20087 AddIn Problem Pin
cecildt29-Sep-08 2:05
cecildt29-Sep-08 2:05 
AnswerRe: VS20087 AddIn Problem Pin
cecildt29-Sep-08 2:41
cecildt29-Sep-08 2:41 
QuestionApplication not closing properly Pin
Chazzysb29-Sep-08 1:26
Chazzysb29-Sep-08 1:26 
AnswerRe: Application not closing properly Pin
HemJoshi29-Sep-08 2:31
HemJoshi29-Sep-08 2:31 
QuestionUnexpected message queue behaviour Pin
Nicholas Butler29-Sep-08 1:11
sitebuilderNicholas Butler29-Sep-08 1:11 
I was helping with this question[^] and decided to actually try out my advice.

Basically, the OP wants to add a load of images to a form, but it takes some time and he wants the form to remain responsive. I suggested using User32.PostMessage with a user message to add each image. After an image has been added, post the message again to do the next image.

What I expected to happen was that any windows messages that were posted to the message queue while an image was being added, would be handled before the next user message was pumped. This appears not to be the case. It seems the windows messages don't get through until all the user messages have been pumped. So, the form is still unresponsive during this time.

My question is: can anyone explain this to me?

This is in my Form. I have simulated adding images with setting a label's text lots of times:

const int MSG = 0x0400;
Queue<int> _Queue = new Queue<int>();

protected override void WndProc( ref Message m )
{
  if ( m.Msg == MSG ) AddImage();
  base.WndProc( ref m );
}

private void button1_Click( object sender, EventArgs e )
{
  for ( int i = 0 ; i < 1000 ; i++ ) _Queue.Enqueue( i );
  Pulse();
}

private void Pulse()
{
  Refresh();
  //Application.DoEvents();
  if ( _Queue.Count > 0 ) User32.PostMessage( Handle, MSG, 0, 0 );
}

private void AddImage()
{
  if ( _Queue.Count > 0 )
  {
    int i = _Queue.Dequeue();
    for ( int x = 0 ; x < ( int ) 1e4 ; x++ ) 
      label1.Text = "hello " + i;
  }
  Pulse();
}


The interesting method is Pulse. I understand the need for Refresh ( because WM_PAINT messages are deferred ), but I don't understand why the nasty Application.DoEvents() is required.

Thanks

Nick

----------------------------------
Be excellent to each other Smile | :)

AnswerRe: Unexpected message queue behaviour Pin
leppie29-Sep-08 1:39
leppie29-Sep-08 1:39 
GeneralRe: Unexpected message queue behaviour Pin
Nicholas Butler29-Sep-08 1:48
sitebuilderNicholas Butler29-Sep-08 1:48 
GeneralRe: Unexpected message queue behaviour Pin
leppie29-Sep-08 2:59
leppie29-Sep-08 2:59 
GeneralRe: Unexpected message queue behaviour Pin
Nicholas Butler29-Sep-08 3:23
sitebuilderNicholas Butler29-Sep-08 3:23 
QuestionConnection problem with MS Exchange Server Pin
free_soul42429-Sep-08 1:02
free_soul42429-Sep-08 1:02 
AnswerRe: Connection problem with MS Exchange Server Pin
Brij29-Sep-08 2:24
mentorBrij29-Sep-08 2:24 
GeneralRe: Connection problem with MS Exchange Server Pin
free_soul42429-Sep-08 17:37
free_soul42429-Sep-08 17:37 
QuestionChange Resolution Pin
Hossein Afyuoni29-Sep-08 0:54
Hossein Afyuoni29-Sep-08 0:54 
AnswerRe: Change Resolution Pin
Giorgi Dalakishvili29-Sep-08 1:29
mentorGiorgi Dalakishvili29-Sep-08 1:29 
Questionreading font files Pin
GSSPriya29-Sep-08 0:51
GSSPriya29-Sep-08 0:51 
AnswerRe: reading font files Pin
Anthony Mushrow29-Sep-08 3:01
professionalAnthony Mushrow29-Sep-08 3:01 
GeneralRe: reading font files Pin
GSSPriya29-Sep-08 19:45
GSSPriya29-Sep-08 19:45 
QuestionAdd Scanner Pin
Pedram Behroozi29-Sep-08 0:05
Pedram Behroozi29-Sep-08 0:05 
AnswerRe: Add Scanner Pin
N a v a n e e t h29-Sep-08 0:12
N a v a n e e t h29-Sep-08 0:12 
GeneralRe: Add Scanner Pin
Hossein Afyuoni29-Sep-08 0:38
Hossein Afyuoni29-Sep-08 0:38 
AnswerRe: Add Scanner Pin
vkuttyp29-Sep-08 18:14
professionalvkuttyp29-Sep-08 18:14 
QuestionCOM object in .net whose threading model is STA, not both Pin
Shao Voon Wong28-Sep-08 23:38
mvaShao Voon Wong28-Sep-08 23:38 

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.