write its own event loop

  • Thread starter Thread starter Lloyd Dupont
  • Start date Start date
L

Lloyd Dupont

I'm doing kind of custom ShowDialog() function, for a class of popping
control.

roughly in it I have
ShowModal()
{
BringToFront()
modal = true;
while(modal)
Application.DoEvents();
}

the problem is, when I tru this on the desktop my CPU usage goes up to 100%
I try to add a Thread.Sleep() before DoEvents(), but that doesn't help.

any way of doing that without having a 100% CPU usage ?
 
Maybe calling Sleep(0) will be enough, provided DoEvents() properly
dispatches the messages in the queue.

-Chris
 
Hi Lloyd,

I did something similar using the code snippet below, tho I don't know what
the cpu usage looks like. You may find it useful.

Chris

private void ShowPanelAsModalDialog(Panel APanel)

{

m_dialogResult = DialogResult.Cancel;


APanel.BringToFront();

APanel.Show();


m_dialogPanel = APanel;

//timer1.Interval = 250;

timer1.Enabled = true;

while (timer1.Enabled)

{

Application.DoEvents();

}

}

private void timer1_Tick(object sender, System.EventArgs e)

{

timer1.Enabled = m_dialogPanel.Visible;

}

private void Dialog_Cancel_Click(object sender, System.EventArgs e)

{

m_dialogResult = DialogResult.Cancel;

m_dialogPanel.Hide();

}

private void Dialog_OK_Click(object sender, System.EventArgs e)

{


m_dialogResult = DialogResult.OK;

m_dialogPanel.Hide();

}
 
Maybe calling Sleep(0) will be enough, provided DoEvents() properly
dispatches the messages in the queue.

-Chris

Of course, you do have [STAThread] attribute on this thread.. And this
is a windows application not a console application.. right?
 
Keep in mind this is the compact framework

--
Chris Tacke, eMVP
Advisory Board Member
www.OpenNETCF.org
---
Windows CE Product Manager
Applied Data Systems
www.applieddata.net

Girish Bharadwaj said:
Maybe calling Sleep(0) will be enough, provided DoEvents() properly
dispatches the messages in the queue.

-Chris

Of course, you do have [STAThread] attribute on this thread.. And this
is a windows application not a console application.. right?
 
hey that's clever !

chris-s said:
Hi Lloyd,

I did something similar using the code snippet below, tho I don't know what
the cpu usage looks like. You may find it useful.

Chris

private void ShowPanelAsModalDialog(Panel APanel)

{

m_dialogResult = DialogResult.Cancel;


APanel.BringToFront();

APanel.Show();


m_dialogPanel = APanel;

//timer1.Interval = 250;

timer1.Enabled = true;

while (timer1.Enabled)

{

Application.DoEvents();

}

}

private void timer1_Tick(object sender, System.EventArgs e)

{

timer1.Enabled = m_dialogPanel.Visible;

}

private void Dialog_Cancel_Click(object sender, System.EventArgs e)

{

m_dialogResult = DialogResult.Cancel;

m_dialogPanel.Hide();

}

private void Dialog_OK_Click(object sender, System.EventArgs e)

{


m_dialogResult = DialogResult.OK;

m_dialogPanel.Hide();

}
 
Back
Top