Questions tagged [message-loop]
70 questions
15
votes
2 answers
Cocoa message loop? (vs. windows message loop)
While trying to port my game engine to mac, I stumble upon one basic (but big) problem. On windows, my main code looks like this (very simplified):
PeekMessage(...) // check for windows messages
switch (msg.message)
{
case WM_QUIT: ...;
case…

scippie
- 2,011
- 1
- 26
- 42
15
votes
1 answer
Code hot swapping in Erlang
I recently saw a video about Erlang on InfoQ,
In that video one of the creators presented how to replace the behavior of a message loop.
He was simply sending a message containing a lambda of the new version of the message loop code, which then was…

Roger Johansson
- 22,764
- 18
- 97
- 193
14
votes
2 answers
How to exit a thread's message loop?
A background-thread can be configured to receive window messages. You would post messages to the thread using PostThreadMessage. What's the correct way to exit that message loop?
Background
Before you can post messages to a background thread, the…

Ian Boyd
- 246,734
- 253
- 869
- 1,219
10
votes
5 answers
Changing a Window's message loop thread
Recently I tried putting a window's message loop in its own thread, and I wondered why it never received any messages, but I have learned that Windows posts messages to the thread that created the window. How do you create a window in one thread and…

Epro
- 673
- 2
- 7
- 9
7
votes
4 answers
C# - Waiting for WinForms Message Loop
I have to write an C# API for registering global hotkeys. To receive the WM_HOTKEY message, I use a System.Windows.Forms.NativeWindow and run an own message loop with System.Windows.Forms.Application.Run(ApplicationContext). When the user wants to…

Jonas W
- 373
- 1
- 4
- 15
7
votes
2 answers
Erlang message loops
How does message loops in erlang work, are they sync when it comes to processing messages?
As far as I understand, the loop will start by "receive"ing a message and then perform something and hit another iteration of the loop.
So that has to be…

Roger Johansson
- 22,764
- 18
- 97
- 193
5
votes
1 answer
Threading 101: What is a Dispatcher?
Once upon a time, I remembered this stuff by heart. Over time, my understanding has diluted and I mean to refresh it.
As I recall, any so called single threaded application has two threads:
a) the primary thread that has a pointer to the main or…

Water Cooler v2
- 51
- 1
- 3
4
votes
2 answers
Implementing a Win32 message loop and creating a Window object with P/Invoke
My main goal is to implement a proper message loop purely with P/Invoke calls that is able to handle USB HID events. Definitely its functionality should be identical with the following code that works well in Windows Forms. This NativeWindow…

tamasf
- 1,068
- 2
- 10
- 22
4
votes
2 answers
Is it possible to use Windows Raw Input API without a window (ie from a console application)?
Is it possible to use Windows Raw Input API without a window (ie from a console application)?
I've tried using RegisterRawInputDevices but my message loops doesn't seem to get any events from GetMessage and hence just 'hangs' there.

Adam M-W
- 3,509
- 9
- 49
- 69
4
votes
2 answers
How to programmatically exit from a second message loop?
I'm trying to create a second message loop to process/filter low level messages asynchronously in C#. It works by creating a hidden form, exposing it's Handle property to be hooked, and run a second message loop in a separate thread. At the moment…

ceztko
- 14,736
- 5
- 58
- 73
4
votes
4 answers
How can a new Form be run on a different thread in C#?
I'm just trying to run a new thread each time a button click even occurs which should create a new form. I tried this in the button click event in the MainForm:
private void button1_Click(object sender, EventArgs e)
{
worker1 = new Thread(new…

SLp
- 135
- 3
- 3
- 11
4
votes
1 answer
.NET's Event Mechanism
In all the books regarding C#/.NET that I have seen till now, when they talk about Events,
they talk about Creating and Consuming Events.
I am curious to understand a bit how it works behind our code - what is the mechanism that runs it.
I know a…

spaceman
- 1,061
- 1
- 11
- 31
4
votes
2 answers
Using async method for message loop in C#
I'm making an online communication application, and I'd like to process messages asynchronously. I found async-await pattern useful in implementing message loop.
Below is what I have got so far:
CancellationTokenSource cts=new…

eivour
- 1,678
- 12
- 20
4
votes
2 answers
How can I terminate a thread that has a seperate message loop?
I am writing a utility unit for the SetWindowsHookEx API.
To use it, I'd like to have an interface like this:
var
Thread: TKeyboardHookThread;
begin
Thread := TKeyboardHookThread.Create(SomeForm.Handle, SomeMessageNumber);
try
…

Jens Mühlenhoff
- 14,565
- 6
- 56
- 113
3
votes
4 answers
Run Message Loop while waiting for WaitHandle
Is there any way to process all Windows messages while the UI thread is waiting on a WaitHandle or other threading primitive?
I realize that it could create very messy reentrancy problems; I want to do it anyway.
EDIT: The wait occurs in the middle…

SLaks
- 868,454
- 176
- 1,908
- 1,964