473,395 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Threading and WndProc - basic question

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
2 4030
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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Zuel | last post by:
Sup everyone! I wrote this code for Tomcat appserver but I am told from an associate that it has threading issues. The basic idea is to store a read only data table for everyone to use. It...
6
by: Turbo_King | last post by:
Hi, I am trying to write a class which creates a window and then assigns a method of the class as the wndproc function for the window so that each instance of the class can handle the messages...
8
by: Michael Culley | last post by:
I have some code that returns an event on a different thread. This is causing all sorts of problems, so I would like to just call a method on the main thread of the app and eliminate the second...
2
by: Phuff | last post by:
I have an application that should run in the system tray while open. It is supposed to be open at all times and I need it to dissapear when the "X" button is pushed on the form...but without...
25
by: MuZZy | last post by:
Hi, I'm currently rewriting some functionality which was using multithredaing for retrieving datasets from database and updating a grid control. I found that the grids (Infragistics UltraGrid,...
14
by: Christian Kaiser | last post by:
We have a component that has no window. Well, no window in managed code - it uses a DLL which itself uses a window, and this is our problem! When the garbage collector runs and removes our...
2
by: Sin Jeong-hun | last post by:
I created a windows form application. It has a Threading.Timer and when the timer ticks it does some work and show a popup window. The problem is that while this program is running if the user...
4
by: Steven | last post by:
I am taking an "advanced" VB.Net course via web at a state university toward an information science degree. This is my second VB class and I am kind of disappointed in it. This week we covered...
19
by: frankiespark | last post by:
Hello all, I was perusing the internet for information on threading when I came across this group. Since there seems to be a lot of good ideas and useful info I thought I'd pose a question. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.