M
Marc ENGEL
Hi all,
I need to implement a Custom Message Loop in my
application.
Instead of calling Application.Run(), I'd like to do it by
myself calling:
while (true)
{
Application.DoEvents()
}
The problem is that when calling this function in a loop,
it will take all the CPU.
In the following thread, the better suggested solution is
to add a Sleep(55):
http://groups.google.com/groups?hl=fr&lr=&ie=UTF-8&oe=UTF-
8&selm=%23AqyL4oBDHA.2208%40TK2MSFTNGP12.phx.gbl
Is there no better solution using a function like
Application.WaitForEvent() that would wait for an event
before triggering the DoEvents:
while (true)
{
Application.WaitForEvent() 'This is the missing function
Application.DoEvents()
}
Maybe I'm old fashion but the Sleep-like solution looks
like polling and should not be used in a multi-threaded
application. Shouldn't there be some synchronisation
function provided by the framework?
Actually by looking at IL from Application.Run() it seems
that something exist but I don't know how to acces this
feature.
Something like:
System.Windows.Forms.Application/ThreadContext::LocalModalM
essageLoop(...)
that finally call the brave old:
PeekMessage and PreProcessMessage
Can I call this? Is it Unsafe?
Your advices are welcome,
Marc
I need to implement a Custom Message Loop in my
application.
Instead of calling Application.Run(), I'd like to do it by
myself calling:
while (true)
{
Application.DoEvents()
}
The problem is that when calling this function in a loop,
it will take all the CPU.
In the following thread, the better suggested solution is
to add a Sleep(55):
http://groups.google.com/groups?hl=fr&lr=&ie=UTF-8&oe=UTF-
8&selm=%23AqyL4oBDHA.2208%40TK2MSFTNGP12.phx.gbl
Is there no better solution using a function like
Application.WaitForEvent() that would wait for an event
before triggering the DoEvents:
while (true)
{
Application.WaitForEvent() 'This is the missing function
Application.DoEvents()
}
Maybe I'm old fashion but the Sleep-like solution looks
like polling and should not be used in a multi-threaded
application. Shouldn't there be some synchronisation
function provided by the framework?
Actually by looking at IL from Application.Run() it seems
that something exist but I don't know how to acces this
feature.
Something like:
System.Windows.Forms.Application/ThreadContext::LocalModalM
essageLoop(...)
that finally call the brave old:
PeekMessage and PreProcessMessage
Can I call this? Is it Unsafe?
Your advices are welcome,
Marc