473,320 Members | 1,825 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,320 software developers and data experts.

Message Queues

Hi,

I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET, i
need to implement this kind of message loop as part of an execution yield, i
dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.

Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet.

Thanks in advance
Neil
Nov 20 '05 #1
16 3811
Look in your help under messagequeues, and message class. For instance, its
already intercepted for you in most cases with the overridable function
WndProc from the Control class. Check out that and it may be a good start.

HTH,
CJ
"Neil Stevens" <ne**********@blueyonder.co.uk> wrote in message
news:uP*************@tk2msftngp13.phx.gbl...
Hi,

I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET, i need to implement this kind of message loop as part of an execution yield, i dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.

Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet.

Thanks in advance
Neil

Nov 20 '05 #2
Look in your help under messagequeues, and message class. For instance, its
already intercepted for you in most cases with the overridable function
WndProc from the Control class. Check out that and it may be a good start.

HTH,
CJ
"Neil Stevens" <ne**********@blueyonder.co.uk> wrote in message
news:uP*************@tk2msftngp13.phx.gbl...
Hi,

I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET, i need to implement this kind of message loop as part of an execution yield, i dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.

Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet.

Thanks in advance
Neil

Nov 20 '05 #3
"Neil Stevens" <ne**********@blueyonder.co.uk> schrieb
I would like to implements a message queue much like i used to in vb6
as below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in
VB.NET, i need to implement this kind of message loop as part of an
execution yield, i dont want to use DoEvents() because of the
propblems i have had with using it in the past and this method has
proved the best in VB6 for yilding execution.


Out of interest: When do you need this?
--
Armin

Nov 20 '05 #4
"Neil Stevens" <ne**********@blueyonder.co.uk> schrieb
I would like to implements a message queue much like i used to in vb6
as below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in
VB.NET, i need to implement this kind of message loop as part of an
execution yield, i dont want to use DoEvents() because of the
propblems i have had with using it in the past and this method has
proved the best in VB6 for yilding execution.


Out of interest: When do you need this?
--
Armin

Nov 20 '05 #5
Sin
> I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET, i need to implement this kind of message loop as part of an execution yield, i dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.

Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet.


Give us more details on what you're really trying to do.

The fact there are threads and that these threads can be priorized in .NET
changes the whole picture. If you want to yield to another application just
lower your main threads priority, or higten the other app's thread, etc...

You don't give us enough info to really know what you want to do so I might
be totally off...

Alex.
Nov 20 '05 #6
Sin
> I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET, i need to implement this kind of message loop as part of an execution yield, i dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.

Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet.


Give us more details on what you're really trying to do.

The fact there are threads and that these threads can be priorized in .NET
changes the whole picture. If you want to yield to another application just
lower your main threads priority, or higten the other app's thread, etc...

You don't give us enough info to really know what you want to do so I might
be totally off...

Alex.
Nov 20 '05 #7
What i have in the application is a form that opens a web document, i have a
method that sets the document property of the web browser control. The html
document has an amount of processing that has to be completed before it can
be shown to the user, so the form is hidden the web browser controls
document property is set to the html page and the html page starts
processing itself.

What i have then is a Yield method which processing the message queue so
that the application doesnt lock up while the html document is processing,
when the document is loaded then the method which sets up the document
property can continue to set up the form sizes and finally show the form.

As i said i have had some problems with the DoEvents method and personally
dont like this for of yielding execution, i have found that during a
DoEvents execution pops off to some other part of the application and i want
to prevent this until the form has fully loaded and been shown. The
following code is an example of the code i have

{Method that navigates to a page in a web browser control}
Set wb = New WebBrowser
wb.Navigate htmlPageToLoad

Dim hDoc as HTMLDocument
Set hDoc = wb.Document
If hDoc Is Nothing Then
Exit Function
End If

Do
Yield()
Loop Until (LCase$(hDoc.ReadyState) = "complete" Or LCase$(hDoc.ReadyState)
= "interactive") And wb.Busy = False

{Returns hDoc if it is not nothing}

' This is the yield method, it process any post message on the stack - not
keyboard or mouse messages
Public Sub Yield()
Dim m As MSG

While PeekMessage(m, 0, 0, 0, PM_REMOVE Or PM_QS_POSTMESSAGE Or
PM_QS_PAINT)
TranslateMessage m
DispatchMessage m
Wend
End Sub

I hope this makes things a little more clearer, i have other parts of the
code where this type of method is used.

I also use the PostMessage to post a close message from a handling UI class
to a form

Public Sub PostCloseMessage(ByVal hWnd As Long)
Posts a WM_CLOSE message to the target hWnd
PostMessage hWnd, WM_CLOSE, 0, 0
End Sub

And would like to know if there is an equivalant .NET Framework method.

Thanks for your time in advance
Neil

"Sin" <br****@hotmail.com> wrote in message
news:NY********************@weber.videotron.net...
I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET,
i
need to implement this kind of message loop as part of an execution
yield, i
dont want to use DoEvents() because of the propblems i have had with
using it in the past and this method has proved the best in VB6 for yilding
execution.

Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet.


Give us more details on what you're really trying to do.

The fact there are threads and that these threads can be priorized in .NET
changes the whole picture. If you want to yield to another application

just lower your main threads priority, or higten the other app's thread, etc...

You don't give us enough info to really know what you want to do so I might be totally off...

Alex.

Nov 20 '05 #8
What i have in the application is a form that opens a web document, i have a
method that sets the document property of the web browser control. The html
document has an amount of processing that has to be completed before it can
be shown to the user, so the form is hidden the web browser controls
document property is set to the html page and the html page starts
processing itself.

What i have then is a Yield method which processing the message queue so
that the application doesnt lock up while the html document is processing,
when the document is loaded then the method which sets up the document
property can continue to set up the form sizes and finally show the form.

As i said i have had some problems with the DoEvents method and personally
dont like this for of yielding execution, i have found that during a
DoEvents execution pops off to some other part of the application and i want
to prevent this until the form has fully loaded and been shown. The
following code is an example of the code i have

{Method that navigates to a page in a web browser control}
Set wb = New WebBrowser
wb.Navigate htmlPageToLoad

Dim hDoc as HTMLDocument
Set hDoc = wb.Document
If hDoc Is Nothing Then
Exit Function
End If

Do
Yield()
Loop Until (LCase$(hDoc.ReadyState) = "complete" Or LCase$(hDoc.ReadyState)
= "interactive") And wb.Busy = False

{Returns hDoc if it is not nothing}

' This is the yield method, it process any post message on the stack - not
keyboard or mouse messages
Public Sub Yield()
Dim m As MSG

While PeekMessage(m, 0, 0, 0, PM_REMOVE Or PM_QS_POSTMESSAGE Or
PM_QS_PAINT)
TranslateMessage m
DispatchMessage m
Wend
End Sub

I hope this makes things a little more clearer, i have other parts of the
code where this type of method is used.

I also use the PostMessage to post a close message from a handling UI class
to a form

Public Sub PostCloseMessage(ByVal hWnd As Long)
Posts a WM_CLOSE message to the target hWnd
PostMessage hWnd, WM_CLOSE, 0, 0
End Sub

And would like to know if there is an equivalant .NET Framework method.

Thanks for your time in advance
Neil

"Sin" <br****@hotmail.com> wrote in message
news:NY********************@weber.videotron.net...
I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET,
i
need to implement this kind of message loop as part of an execution
yield, i
dont want to use DoEvents() because of the propblems i have had with
using it in the past and this method has proved the best in VB6 for yilding
execution.

Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet.


Give us more details on what you're really trying to do.

The fact there are threads and that these threads can be priorized in .NET
changes the whole picture. If you want to yield to another application

just lower your main threads priority, or higten the other app's thread, etc...

You don't give us enough info to really know what you want to do so I might be totally off...

Alex.

Nov 20 '05 #9
* "Neil Stevens" <ne**********@blueyonder.co.uk> scripsit:
I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET, i
need to implement this kind of message loop as part of an execution yield, i
dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.


I think you can use the same code in VB.NET, but why do you need that?
Maybe there is a better, managed solution.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #10
* "Neil Stevens" <ne**********@blueyonder.co.uk> scripsit:
I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET, i
need to implement this kind of message loop as part of an execution yield, i
dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.


I think you can use the same code in VB.NET, but why do you need that?
Maybe there is a better, managed solution.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #11
"Neil Stevens" <ne**********@blueyonder.co.uk> schrieb
I hope this makes things a little more clearer, i have other parts of
the code where this type of method is used.


I'd wait for the Documentcomplete event, then show the form. Or, as the user
wants to know what's going on, I'd show the Form first.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #12
"Neil Stevens" <ne**********@blueyonder.co.uk> schrieb
I hope this makes things a little more clearer, i have other parts of
the code where this type of method is used.


I'd wait for the Documentcomplete event, then show the form. Or, as the user
wants to know what's going on, I'd show the Form first.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #13
Sin
> What i have in the application is a form that opens a web document, i have
a
method that sets the document property of the web browser control. The html document has an amount of processing that has to be completed before it can be shown to the user, so the form is hidden the web browser controls
document property is set to the html page and the html page starts
processing itself.

What i have then is a Yield method which processing the message queue so
that the application doesnt lock up while the html document is processing,
when the document is loaded then the method which sets up the document
property can continue to set up the form sizes and finally show the form.

As i said i have had some problems with the DoEvents method and personally
dont like this for of yielding execution, i have found that during a
DoEvents execution pops off to some other part of the application and i want to prevent this until the form has fully loaded and been shown.


I haven't had to work with a similar problem but I suppose you could kick a
thread in which you would assign the url to the web control and then do the
sizing stuff.... All while your mean thread continues to process events...
If you need to prevent mouse/keyboard input while that happens, just disable
the main form at start of thread and re-enable at end of thread...

Would that work?

Alex.
Nov 20 '05 #14
Sin
> What i have in the application is a form that opens a web document, i have
a
method that sets the document property of the web browser control. The html document has an amount of processing that has to be completed before it can be shown to the user, so the form is hidden the web browser controls
document property is set to the html page and the html page starts
processing itself.

What i have then is a Yield method which processing the message queue so
that the application doesnt lock up while the html document is processing,
when the document is loaded then the method which sets up the document
property can continue to set up the form sizes and finally show the form.

As i said i have had some problems with the DoEvents method and personally
dont like this for of yielding execution, i have found that during a
DoEvents execution pops off to some other part of the application and i want to prevent this until the form has fully loaded and been shown.


I haven't had to work with a similar problem but I suppose you could kick a
thread in which you would assign the url to the web control and then do the
sizing stuff.... All while your mean thread continues to process events...
If you need to prevent mouse/keyboard input while that happens, just disable
the main form at start of thread and re-enable at end of thread...

Would that work?

Alex.
Nov 20 '05 #15
Neil,
Is there a way that i can implements something similar to this in VB.NET, i
Yes: System.Windows.Forms.Application.DoEvents

Or use Threads.
dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution. VB.NET is NOT VB6, problems you may or may not have had in VB6 do not
necessarily exist in VB.NET. New runtime, new framework, and sad to say new
problems.
Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet. My first advice would be not to attempt it: as you are probably causing more
problems then helping in either VB6 or VB.NET, however you can use the same
technique in VB.NET that you used in VB6!

Declare your functions (PeekMessage,TranslateMessage,DispatchMessage) at the
top of your source file & call the them. Remember that Integer is 32bit in
VB.NET while only 16 bit in VB6.

I would seriously look at using a thread rather then some "hack" that may
cause other "hidden" problems...

Hope this helps
Jay

"Neil Stevens" <ne**********@blueyonder.co.uk> wrote in message
news:uP*************@tk2msftngp13.phx.gbl... Hi,

I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET, i need to implement this kind of message loop as part of an execution yield, i dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.

Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet.

Thanks in advance
Neil

Nov 20 '05 #16
Neil,
Is there a way that i can implements something similar to this in VB.NET, i
Yes: System.Windows.Forms.Application.DoEvents

Or use Threads.
dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution. VB.NET is NOT VB6, problems you may or may not have had in VB6 do not
necessarily exist in VB.NET. New runtime, new framework, and sad to say new
problems.
Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet. My first advice would be not to attempt it: as you are probably causing more
problems then helping in either VB6 or VB.NET, however you can use the same
technique in VB.NET that you used in VB6!

Declare your functions (PeekMessage,TranslateMessage,DispatchMessage) at the
top of your source file & call the them. Remember that Integer is 32bit in
VB.NET while only 16 bit in VB6.

I would seriously look at using a thread rather then some "hack" that may
cause other "hidden" problems...

Hope this helps
Jay

"Neil Stevens" <ne**********@blueyonder.co.uk> wrote in message
news:uP*************@tk2msftngp13.phx.gbl... Hi,

I would like to implements a message queue much like i used to in vb6 as
below:-

dim myMsg as MSG
while (PeekMessage(myMsg, hWnd, 0, 0))
if myMsg.Msg = WM_QUIT Then
End
end if
TranslateMessage(myMsg)
DispatchMessage(myMsg)
wend
(I know the syntax probably isnt correct)

Is there a way that i can implements something similar to this in VB.NET, i need to implement this kind of message loop as part of an execution yield, i dont want to use DoEvents() because of the propblems i have had with using
it in the past and this method has proved the best in VB6 for yilding
execution.

Could somebody provide some example code of how to do this in VB.NET or
point me to a good resource on the internet.

Thanks in advance
Neil

Nov 20 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Aki Niimura | last post by:
Hello everyone. I'm trying to control a program from a Python program using IPC. Although using a socket is a common choice for such applications, I would like to use SysV message queues...
0
by: badtemper | last post by:
Is there any way to use perl or any other programming language to perform a "qchk -A" from a web page and see the listing? My problem is that I manage the network for a medical facility that is...
4
by: Tingo | last post by:
Hi all, Is it possible to create a message queue with a specific ID? I want to do this because I'm trying to write a piece of software which restores communicating processes (which communicate...
1
by: Susan | last post by:
I've had to separate my application into 2 apps. I need to second app to poll the message queue for certain messages from the main app. Does someone have some code on how to do this? I have the...
3
by: Brian Keating | last post by:
hello, doesn anyone know how to deploy message queues? I've got a program which uses message queues and i wish to deploy it, one click deployment in vs2005 doesn't allow me to specify message...
0
by: sam | last post by:
Hi, I have windows services appliaction. Application reads message from MS message queuing. I have short code example below of my application. I have different process points these point have...
0
by: sam | last post by:
Hi, Im using windows froms exe application to read and send messages to private message queues. Using threads how can I keep reading all the messages from MS private message queuing without...
2
by: DBC User | last post by:
Hi All, I am going to develop two application which will talk to each other using MSMQ. I have couple of questions 1. Do we need to install anything extra in client PC to use MSMQ? Since...
1
by: Safalra | last post by:
A long time ago when I used a browser that didn't support the shift or unshift methods of the array object, I came up with an implementation of queues that guaranteed amortised constant time...
1
by: ericstein81 | last post by:
I am trying to write a program that uses three queues for inputs of numbers. The problem i am having is I am not quite sure how to designate the seperate queues. can they be named as queue(a),...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.