473,503 Members | 1,646 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Similar topics

0
2749
by: amit | last post by:
I want to find out that if there is a mechanism to find a text inside a C# file and replace it with another string. I am using DTE to do it, the find proerty does it, the results are getting...
0
2563
by: AMIT PUROHIT | last post by:
hi, this is a qry which I m stuck up with I want to find out that if there is a mechanism to find a text inside a C# file and replace it with another string. I am using DTE(EnvDTE) to do it,...
0
2102
by: amit | last post by:
hi I have created a tool which does a find and replace thru DTE, now after it is done, it opens up a window, "FIND REACHED THE STARTING POINT OF SEARCH" I want to disbale this window...
0
1699
by: Craig | last post by:
Hi, Would appreciate any help you guys have to offer. On calling beginPeek on instantiation of a MessageQueue, EndPeek throws a MessageQueueException. If the queue exists already, the exception is...
5
3001
by: Mike Labosh | last post by:
In VB 6, the Form_QueryUnload event had an UnloadMode parameter that let me find out *why* a form is unloading, and then conditionally cancel the event. In VB.NET, the Closing event passes a...
3
7178
by: DJTN | last post by:
I'm getting the following error when I try to compile my setup project in VS 2002. I have re-installed the .net framework 1.1 and it didnt solve the problem. WARNING: Unable to find dependency...
3
16471
by: David T. Ashley | last post by:
Hi, Red Hat Enterprise Linux 4.X. I'm writing command-line PHP scripts for the first time. I get the messages below. What do they mean? Are these operating system library modules, or...
0
11251
by: Derek | last post by:
I am creating an intranet using Visual Web Developer Express Edition. Everything has been working OK until yesterday when I started getting 62 messages all beginning "Could not find schema...
0
7198
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
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6979
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
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.