user defined window message

  • Thread starter Thread starter Nathan Smith
  • Start date Start date
N

Nathan Smith

I have an app that has several background threads running, and I want to use
a user-defined message to tell the main form that I want it to update a
object it created on startup.

I know this capability is in VC++ using the RegisterMessage and PostMessage
functions, but is there anything like this in VB.net?

Thanks.
 
I have an app that has several background threads running, and I want to use
a user-defined message to tell the main form that I want it to update a
object it created on startup.

I know this capability is in VC++ using the RegisterMessage and PostMessage
functions, but is there anything like this in VB.net?

Thanks.

You can certainly use RegisterMessage and PostMessge from VB.NET using
P/Invoke - but, wouldn't it be simpler to just let your background
threads fire an event back to the main thread?
 
Tom Shelton said:
You can certainly use RegisterMessage and PostMessge from VB.NET using
P/Invoke - but, wouldn't it be simpler to just let your background
threads fire an event back to the main thread?

The thing to be wary of when using events or a direct notification is that
the call will then need to be marshalled over to the UI thread. This can be
achieved a couple of ways, such as using the BackgroundWorker component for
the background threads, or using normal threading and then doing an
Control.Invoke call to get the message onto the main thread.
 
Nathan Smith said:
I have an app that has several background threads running, and I want to
use
a user-defined message to tell the main form that I want it to update a
object it created on startup.

I know this capability is in VC++ using the RegisterMessage and
PostMessage
functions, but is there anything like this in VB.net?

You do not even need 'RegisterWindowMessage' if you are sending messages
inside your application. Instead, you can define your own messages with
message codes in the range &H8000 through &HBFFF.

However, I am just curious why you are not using
'Control.Invoke'/'Control.BeginInvoke'/'Control.InvokeRequired' instead to
access the controls from within the threads.
 
Specifically, I am trying to add logging information to a file that is
created under the main form. So I need some way to update the log file from
multiple threads in a thread-safe manner. This also means I need someway to
pass data to the handler much like Win32 messaging allows.
 
Back
Top