468,504 Members | 1,986 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,504 developers. It's quick & easy.

How do I find which MessageQueueErrorCode it is?

I have been developing an app in VB.Net, using a simple form and a
button to kick off a class that starts asynchronously receiving from
a MessageQueue. It's been working fine, but now I'm moving toward
converting it to a Windows Service, so I switched from instantiating
the clsMsgReceiver class at the Button_Click to a simple Main() that
does the same thing.

I'm stumped -- when started from Main(), the BeginReceive() works only
if there is a message waiting in the MessageQueue when it starts. It
will then process all the messages until the MessageQueue is empty,
and continue waiting for further messages. But if the MessageQueue
is empty when the BeginReceive() starts, it throws an exception. I
tried looking at the MessageQueueErrorCode in the Catch, and it says
" -1073741536". I can see the Enumeration for the error code, but
have not found any way to find out which one of the many errors is
-1073741536.

How do I get that, and better yet, any idea why it would work
correctly when called from a Form button but not from Main()?

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #1
7 3105
Well, I found a workaround. A code example had a function
IsQueueEmpty that uses the MessageQueue.Peek() method to see if the
queue is empty. I added a while loop to the beginning of the thread
that kicks off the receiver, and it waits there till there's
something in the MessageQueue before instantiating the class.

Still, anyone know why it needs that, if the asynchronous model is
supposed to be able to do that by itself???

Thanks

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #2
felecha,
If you are writing a Windows Service why are you using BeginReceive in the
Sub Main?

I normally only start the Service itself in Sub Main, then call BeginReceive
in the OnStart method of the service. As normally you do not want to be
waiting for messages, if the service is simply loaded & not started.

Within the ReceiveCompleted event, I call EndReceive using e.AsyncResult.
Note I am using the MessageQueue.ReceiveCompeleted event instead of passing
a delegate to the BeginReceive method.

Which version of the OS, VS.NET & .NET? I'm using VS.NET 2003 (.NET 1.1) on
Windows XP Pro and I am able to call BeginReceive in the OnStart of my
service and it patiently waits for a message to arrive.

Hope this helps
Jay
"felecha" <fe*******@yahoo-dot-com.no-spam.invalid> wrote in message
news:40**********@127.0.0.1...
I have been developing an app in VB.Net, using a simple form and a
button to kick off a class that starts asynchronously receiving from
a MessageQueue. It's been working fine, but now I'm moving toward
converting it to a Windows Service, so I switched from instantiating
the clsMsgReceiver class at the Button_Click to a simple Main() that
does the same thing.

I'm stumped -- when started from Main(), the BeginReceive() works only
if there is a message waiting in the MessageQueue when it starts. It
will then process all the messages until the MessageQueue is empty,
and continue waiting for further messages. But if the MessageQueue
is empty when the BeginReceive() starts, it throws an exception. I
tried looking at the MessageQueueErrorCode in the Catch, and it says
" -1073741536". I can see the Enumeration for the error code, but
have not found any way to find out which one of the many errors is
-1073741536.

How do I get that, and better yet, any idea why it would work
correctly when called from a Form button but not from Main()?

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 20 '05 #3
Jay - That was a blooper. I don't call BeginReceive from Main.

I wrote a class called clsMsgReceiver, in which I create a
MessageQueue, add a handler for the ReceiveCompleted event, and then
call BeginReceive(). The ReceiveCompleted handler gets the incoming
message with EndReceive(), processes it, and calls BeginReceive()
again.

I'm a rookie, looking for code samples in Help and in a textbook I
bought. The above worked fine when I first built it with a basic
Form with one button. The button_click() handler did nothing more
than

dim msgrcvr as new clsMsgReceiver

I haven't yet even started with making it a Service. Services are
also new territory and I tried some sample code last week for another
task in our project, and got that to run OK when I rebooted. So I
know what OnStart is. But for this one I've gone no farther yet than
dropping the instantiation with the button, and instead created a
Main where I again simply called

dim msgrcvr as new clsMsgReceiver

Then I found that it died immediately and someone told me, "You dummy,
Main instantiates the class and then dies. Do it with a thread." So
I learned something about threads and presently have a module like
this:

Module modMain

Public Sub main()
Dim WorkerThread As New Thread(AddressOf
sub_StartMessageQueue)
WorkerThread.Start()
While True
Thread.CurrentThread.Sleep(1000)
End While
End Sub

Private Sub sub_StartMessageQueue()
Dim loMessageQueueReceiver As New clsMessageReceiver
End Sub

End Module
That worked to keep it alive, but then I found the curious behavior
with freezing if the MessageQueue is empty when it starts. I found a
code sample that used a static method IsQueueEmpty that Peek()s to
see if there's a Message there and added to sub_StartMessageQueue():

[code:1:ff9e363d35]
Private Sub sub_StartMessageQueue()
While clsMessageReceiver.IsQueueEmpty = True
Thread.CurrentThread.Sleep(100)
End While
Dim loMessageReceiver As New clsMessageQueueReceiver
End Sub
[/code:1:ff9e363d35]
So far it works. Maybe when I build it into a Service your OnStart
idea will work without the IsQueueEmpty.

So I'm just banging around, trying things. I'm just 6 months out of
school, where I had one course in VB 6, and into the deep end of the
pool. I love it, but it's maddening at times. Look for things that
work, try them, keep looking if they don't.

I have Win XP Pro, VS.Net 2003, v. 1.1.4322.

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #4
felecha,
I have to ask: What do you want?

Do you want your MessageQueue to work in a Windows Service (I know
BeginReceive does).

Or do you want your MessageQueue to work in a "console application", so you
can convert it to a Windows Service later.

IMHO it doesn't really make sense to spend time getting the "console
application" to work, when ultimately you are going to make a Windows
Service.
If you are using BeginReceive, you should NOT be creating a thread! As
BeginReceive implicitly creates a thread for you. The other person in
correct in that you should NOT allow your Sub Main to exit.

I would recommend you start with a Windows Service project and add code
similiar to:

Protected Overridse Sub OnStart(ByVal args() As String)
queueRequest.BeginReceive()
End Sub

Private Sub queueRequest_ReceiveCompleted(ByVal sender As Object, _
ByVal e As System.Messaging.ReceiveCompletedEventArgs) _
Handles queueRequest.ReceiveCompleted
Dim msg As Message = queueRequest.EndReceive(e.AsyncResult)

' process the above message

queueRequest.BeginReceive() ' wait for the next message
End Sub

Where queueRequest is a MessageQueue object that was dropped on the Windows
Service designer. Note the above code needs to be added to the code behind
the Windows Service designer itself.

I've tested the above with private queues, I am not setup yet to try public
queues. Note the above code will patiently wait for a message to arrive on
the queue.

The framework itself will handle putting the BeginReceive on its own thread
in the ThreadPool.
dim msgrcvr as new clsMsgReceiver
While clsMessageReceiver.IsQueueEmpty = True
Dim loMessageReceiver As New clsMessageQueueReceiver
How many message receiver classes do you have??? I've seen at least three in
your post? Which makes me want to ask, how many times are you opening the
MessageQueue & how many MessageQueue objects do you have referring to the
Win32 message queue itself?

Hope this helps
Jay

"felecha" <fe*******@yahoo-dot-com.no-spam.invalid> wrote in message
news:40**********@127.0.0.1... Jay - That was a blooper. I don't call BeginReceive from Main.

I wrote a class called clsMsgReceiver, in which I create a
MessageQueue, add a handler for the ReceiveCompleted event, and then
call BeginReceive(). The ReceiveCompleted handler gets the incoming
message with EndReceive(), processes it, and calls BeginReceive()
again.

I'm a rookie, looking for code samples in Help and in a textbook I
bought. The above worked fine when I first built it with a basic
Form with one button. The button_click() handler did nothing more
than

dim msgrcvr as new clsMsgReceiver

I haven't yet even started with making it a Service. Services are
also new territory and I tried some sample code last week for another
task in our project, and got that to run OK when I rebooted. So I
know what OnStart is. But for this one I've gone no farther yet than
dropping the instantiation with the button, and instead created a
Main where I again simply called

dim msgrcvr as new clsMsgReceiver

Then I found that it died immediately and someone told me, "You dummy,
Main instantiates the class and then dies. Do it with a thread." So
I learned something about threads and presently have a module like
this:

Module modMain

Public Sub main()
Dim WorkerThread As New Thread(AddressOf
sub_StartMessageQueue)
WorkerThread.Start()
While True
Thread.CurrentThread.Sleep(1000)
End While
End Sub

Private Sub sub_StartMessageQueue()
Dim loMessageQueueReceiver As New clsMessageReceiver
End Sub

End Module
That worked to keep it alive, but then I found the curious behavior
with freezing if the MessageQueue is empty when it starts. I found a
code sample that used a static method IsQueueEmpty that Peek()s to
see if there's a Message there and added to sub_StartMessageQueue():

[code:1:ff9e363d35]
Private Sub sub_StartMessageQueue()
While clsMessageReceiver.IsQueueEmpty = True
Thread.CurrentThread.Sleep(100)
End While
Dim loMessageReceiver As New clsMessageQueueReceiver
End Sub
[/code:1:ff9e363d35]
So far it works. Maybe when I build it into a Service your OnStart
idea will work without the IsQueueEmpty.

So I'm just banging around, trying things. I'm just 6 months out of
school, where I had one course in VB 6, and into the deep end of the
pool. I love it, but it's maddening at times. Look for things that
work, try them, keep looking if they don't.

I have Win XP Pro, VS.Net 2003, v. 1.1.4322.

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---

Nov 20 '05 #5
Jay,

It helps tremendously. I won't be able to try it until tomorrow, but
I'm eager.

As a rookie, I figured that it would be better to get the guts of the
thing working, then do it into a Service. I have done only one brief
instance of building a Service, where I looked up the chapter on how
to do it and followed along, using something I had that was already
working on its own.

So for this task I thought that the development and debugging would be
painfully slow if I had to rebuild and then go to the command prompt
and do the uninstall/install thing. I wrote a batch to do that, but
it was still slow. For me, development is often more like
exploration - trying to figure out what to do and how to do it.
Learn by doing, dig into Help or a textbook, go to forums, etc.

I have only begun to learn about threads, and am glad to learn about
the BeginReceive having its own. So much to learn!

And I've been hasty in posting to the forum. There's only one class.
The first line

dim msgrcvr as ...

was just an illustration, so to speak, of what I was doing. Later
when I cut and pasted the code from Main I didn't notice that it was
inconsistent.

Does everybody in this business learn this way? I'm persistent, and
really fired up with interest in software, but golly I spend a lot of
time digging and groping and banging my head against things.

thanks

Felecha

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #6
felecha,
So for this task I thought that the development and debugging would be
painfully slow if I had to rebuild and then go to the command prompt
and do the uninstall/install thing. I wrote a batch to do that, but I either create a setup project, then right click on the setup project to do
the Install, which will automatically do the uninstall.

The other option is to add installutil to "Tools - External Tools". Twice
once of install & once for uninstall. Of course you could call your batch
file with "Tools - External Tools" also.

Does everybody in this business learn this way? I'm persistent, and
really fired up with interest in software, but golly I spend a lot of
time digging and groping and banging my head against things. I suspect a number of people learn that way, as its human nature.

Hope this helps
Jay

"felecha" <fe*******@yahoo-dot-com.no-spam.invalid> wrote in message
news:40********@127.0.0.1... Jay,

It helps tremendously. I won't be able to try it until tomorrow, but
I'm eager.

As a rookie, I figured that it would be better to get the guts of the
thing working, then do it into a Service. I have done only one brief
instance of building a Service, where I looked up the chapter on how
to do it and followed along, using something I had that was already
working on its own.

So for this task I thought that the development and debugging would be
painfully slow if I had to rebuild and then go to the command prompt
and do the uninstall/install thing. I wrote a batch to do that, but
it was still slow. For me, development is often more like
exploration - trying to figure out what to do and how to do it.
Learn by doing, dig into Help or a textbook, go to forums, etc.

I have only begun to learn about threads, and am glad to learn about
the BeginReceive having its own. So much to learn!

And I've been hasty in posting to the forum. There's only one class.
The first line

dim msgrcvr as ...

was just an illustration, so to speak, of what I was doing. Later
when I cut and pasted the code from Main I didn't notice that it was
inconsistent.

Does everybody in this business learn this way? I'm persistent, and
really fired up with interest in software, but golly I spend a lot of
time digging and groping and banging my head against things.

thanks

Felecha

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 20 '05 #7
Thanks again

Hi Ho Hi Ho it's off to work I go

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by amit | last post: by
reply views Thread by AMIT PUROHIT | last post: by
5 posts views Thread by Mike Labosh | last post: by
3 posts views Thread by David T. Ashley | last post: by
reply views Thread by Derek | last post: by
3 posts views Thread by gieforce | last post: by
reply views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.