473,549 Members | 2,784 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I find which MessageQueueErr orCode 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 MessageQueueErr orCode 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 3285
Well, I found a workaround. A code example had a function
IsQueueEmpty that uses the MessageQueue.Pe ek() 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 ReceiveComplete d event, I call EndReceive using e.AsyncResult.
Note I am using the MessageQueue.Re ceiveCompeleted 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*******@yaho o-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 MessageQueueErr orCode 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 ReceiveComplete d event, and then
call BeginReceive(). The ReceiveComplete d 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(AddressO f
sub_StartMessag eQueue)
WorkerThread.St art()
While True
Thread.CurrentT hread.Sleep(100 0)
End While
End Sub

Private Sub sub_StartMessag eQueue()
Dim loMessageQueueR eceiver As New clsMessageRecei ver
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_StartMessag eQueue():

[code:1:ff9e363d 35]
Private Sub sub_StartMessag eQueue()
While clsMessageRecei ver.IsQueueEmpt y = True
Thread.CurrentT hread.Sleep(100 )
End While
Dim loMessageReceiv er As New clsMessageQueue Receiver
End Sub
[/code:1:ff9e363d 35]
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.co m 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.Be ginReceive()
End Sub

Private Sub queueRequest_Re ceiveCompleted( ByVal sender As Object, _
ByVal e As System.Messagin g.ReceiveComple tedEventArgs) _
Handles queueRequest.Re ceiveCompleted
Dim msg As Message = queueRequest.En dReceive(e.Asyn cResult)

' process the above message

queueRequest.Be ginReceive() ' 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 clsMessageRecei ver.IsQueueEmpt y = True
Dim loMessageReceiv er As New clsMessageQueue Receiver
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*******@yaho o-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 ReceiveComplete d event, and then
call BeginReceive(). The ReceiveComplete d 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(AddressO f
sub_StartMessag eQueue)
WorkerThread.St art()
While True
Thread.CurrentT hread.Sleep(100 0)
End While
End Sub

Private Sub sub_StartMessag eQueue()
Dim loMessageQueueR eceiver As New clsMessageRecei ver
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_StartMessag eQueue():

[code:1:ff9e363d 35]
Private Sub sub_StartMessag eQueue()
While clsMessageRecei ver.IsQueueEmpt y = True
Thread.CurrentT hread.Sleep(100 )
End While
Dim loMessageReceiv er As New clsMessageQueue Receiver
End Sub
[/code:1:ff9e363d 35]
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.co m 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*******@yaho o-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
2758
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 displayed in a find results window pane , but I m not able to programmatically take the contents of the pane. DTE.Find.FindWhat = "catch"...
0
2568
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, the find proerty does it, the results are getting displayed in a find results window pane , but I m not able to programmatically take the contents...
0
2108
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 programmatically. how should i do it this is a partial code Dim dsData As DataSe
0
1701
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 not thrown, but when I just create the queue and call BeginPeek, the exception is thrown on calling EndPeek. The MessageQueueErrorCode of the...
5
3008
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 CancelEventArgs that lets me cancel the Close() operation, but is there still any way to find out *why* a form is closing? This app as a form that...
3
7186
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 'mscorlib' (Signature='B77A5C561934E089' Version='1.0.5000.0') of assembly 'System.dll' WARNING: Unable to find dependency 'mscorlib'...
3
16489
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 something in PHP that I don't have? Do I need to install more Linux packages? Or adjust PHP in some way?
0
11254
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 information for the". I am using Cassini as the web server on my PCand I can still run my site from within VWD. Does anyone know what I have done to cause...
0
7518
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7446
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7956
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7469
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7808
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6040
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
3498
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1935
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
757
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.