By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,894 Members | 1,937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,894 IT Pros & Developers. It's quick & easy.

Threading and WndProc - basic question

P: n/a
Hi,

I'm overriding WndProc to process some custom messages like so:

protected override void WndProc(ref Message m)
{

if (m.Msg == ImageFileMsg.MSG_IF_NEW_DATA)
{
ProcessNewDataMessage(m);
}
base.WndProc(ref m);
}

I receive one of these messages every 100ms or so for a few seconds.
This locks up my user interface completely until this is complete which
isn't ideal as each time I get a message I want to update a textbox on
my form.

I'm not sure if my solution is to use threading? I've never used
threads in .NET before, but my understanding is that if I use threading
I'll have to use delegates for my methods which update my form
controls, and these are all translated into messages which go through
WndProc. Is it possible for me to get my ProcessNewDataMessage to work
in a separate thread bearing in mind it's being called from WndProc? Or
will I encounter problems?

Sep 26 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Chris Ashley <ch***********@gmail.comwrote:
I'm overriding WndProc to process some custom messages like so:

protected override void WndProc(ref Message m)
{

if (m.Msg == ImageFileMsg.MSG_IF_NEW_DATA)
{
ProcessNewDataMessage(m);
}
base.WndProc(ref m);
}

I receive one of these messages every 100ms or so for a few seconds.
This locks up my user interface completely until this is complete which
isn't ideal as each time I get a message I want to update a textbox on
my form.

I'm not sure if my solution is to use threading? I've never used
threads in .NET before, but my understanding is that if I use threading
I'll have to use delegates for my methods which update my form
controls, and these are all translated into messages which go through
WndProc. Is it possible for me to get my ProcessNewDataMessage to work
in a separate thread bearing in mind it's being called from WndProc? Or
will I encounter problems?
What does ProcessNewDataMessage need to do? If it's doing some
relatively heavy lifting, I suspect I'd extract all the relevant
information from the message, work on it in another thread (and there
are various options for doing that) and then update the UI using a
delegate. If ProcessNewDataMessage needs to do a lot of UI updating all
in one go, you might want to have a single delegate that takes all the
parameters it needs so you can do it all in one call. (That needn't
mean multiple parameters - it could be a single parameter of a new type
called something like UpdateInformation which has all the relevant info
in it.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Sep 26 '06 #2

P: n/a

"Chris Ashley" <ch***********@gmail.comwrote in message
news:11**********************@i3g2000cwc.googlegro ups.com...
| Hi,
|
| I'm overriding WndProc to process some custom messages like so:
|
| protected override void WndProc(ref Message m)
| {
|
| if (m.Msg == ImageFileMsg.MSG_IF_NEW_DATA)
| {
| ProcessNewDataMessage(m);
| }
| base.WndProc(ref m);
| }
|
| I receive one of these messages every 100ms or so for a few seconds.
| This locks up my user interface completely until this is complete which
| isn't ideal as each time I get a message I want to update a textbox on
| my form.
|
| I'm not sure if my solution is to use threading? I've never used
| threads in .NET before, but my understanding is that if I use threading
| I'll have to use delegates for my methods which update my form
| controls, and these are all translated into messages which go through
| WndProc. Is it possible for me to get my ProcessNewDataMessage to work
| in a separate thread bearing in mind it's being called from WndProc? Or
| will I encounter problems?
|

What do you mean exactly with blocking your UI? If you really receive a
ImageFileMsg.MSG_IF_NEW_DATA message every 100 msec. and you update the
Textbox in your ProcessNewDataMessage(), which means that you update the UI
every 100 msec, this is not what I would call blocking the UI.
What's the service time of the method, and what exactly are you doing in
this method? Is the method CPU bound? Does it block etc... ?

Willy.

Sep 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.