[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

write its own event loop

Lloyd Dupont

10/14/2003 11:36:00 PM

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 ?


6 Answers

Chris Tacke, eMVP

10/15/2003 12:08:00 AM

0

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

-Chris


"Lloyd Dupont" <net.galador@ld> wrote in message
news:u2X6gvqkDHA.2244@TK2MSFTNGP12.phx.gbl...
> 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 ?
>
>


chris-s

10/15/2003 7:26:00 AM

0

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();

}





"Lloyd Dupont" <net.galador@ld> wrote in message
news:u2X6gvqkDHA.2244@TK2MSFTNGP12.phx.gbl...
> 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 ?
>
>


Girish Bharadwaj

10/15/2003 1:57:00 PM

0

Chris Tacke, eMVP wrote:

> Maybe calling Sleep(0) will be enough, provided DoEvents() properly
> dispatches the messages in the queue.
>
> -Chris
>
>
> "Lloyd Dupont" <net.galador@ld> wrote in message
> news:u2X6gvqkDHA.2244@TK2MSFTNGP12.phx.gbl...
>
>>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 ?
>>
>>
>
>
>

Of course, you do have [STAThread] attribute on this thread.. And this
is a windows application not a console application.. right?
--
Girish Bharadwaj

Chris Tacke, eMVP

10/15/2003 4:27:00 PM

0

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" <girishb@nowhere> wrote in message
news:egKvARykDHA.3688@TK2MSFTNGP11.phx.gbl...
> Chris Tacke, eMVP wrote:
>
> > Maybe calling Sleep(0) will be enough, provided DoEvents() properly
> > dispatches the messages in the queue.
> >
> > -Chris
> >
> >
> > "Lloyd Dupont" <net.galador@ld> wrote in message
> > news:u2X6gvqkDHA.2244@TK2MSFTNGP12.phx.gbl...
> >
> >>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 ?
> >>
> >>
> >
> >
> >
>
> Of course, you do have [STAThread] attribute on this thread.. And this
> is a windows application not a console application.. right?
> --
> Girish Bharadwaj
>


Girish Bharadwaj

10/15/2003 5:07:00 PM

0

Chris Tacke, eMVP wrote:

> Keep in mind this is the compact framework
>
Oops.. Crossposted to SDK newsgroup too..

--
Girish Bharadwaj

Lloyd Dupont

10/16/2003 2:16:00 AM

0

hey that's clever !

"chris-s" <chris-s@mailcity.com> wrote in message
news:O%23jLH3ukDHA.2488@TK2MSFTNGP12.phx.gbl...
> 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();
>
> }
>
>
>
>
>
> "Lloyd Dupont" <net.galador@ld> wrote in message
> news:u2X6gvqkDHA.2244@TK2MSFTNGP12.phx.gbl...
> > 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 ?
> >
> >
>
>