Hi. (apologies if the cross posting isn't appropriate) I seem to have a problem with the lifetime of a variable when used with the thread pool and msmq (I wouldn't know how to replicate the behaviour without msmq sorry)
This is the error I get when my application calls BeginPeek - Receive - QueueWorkerItem - BeginPeek within the ide running under debug. The queue is public and on another machine. An unhandled exception of type 'System.NullReferenceException' ocurred in Unknown Module Additional Information - object reference not set to an instance of an object. First of all I place 2000 messages in the queue 124/126 bytes in length a simple string. Then I start my receive program that does the following - private MessageQueue mq = new MessageQueue(); private void ProcessWorkRequest(object data) { string adj = (string)data; FileStream fs = new FileStream( @"C:\Msmqrec" + Thread.CurrentThread.GetHashCode().ToString() + " .txt", FileMode.Create, FileAccess.Write); StreamWriter sw = new StreamWriter(fs, System.Text.Encoding.ASCII ); sw.Write(adj); sw.Flush(); fs.Close(); } private void OnCommandComplete( object sender, PeekCompletedEventArgs async ) { MessageQueue mq = (MessageQueue)sender; System.Messaging.Message msg = mq.EndPeek( async.AsyncResult ); mq.Receive(); string adj = (string)msg.Body; ThreadPool.QueueUserWorkItem( new WaitCallback( ProcessWorkRequest ), adj ); mq.BeginPeek(); } private void button1_Click(object sender, System.EventArgs e) { mq = new MessageQueue( @"Mortimus\deliveryrequests"); mq.Formatter = new XmlMessageFormatter( new Type[] { typeof( string ) } ); mq.PeekCompleted += new PeekCompletedEventHandler( OnCommandComplete ); mq.BeginPeek(); } Running the application I get the error at spurious times never the same amount of messages processed. If you'd like the source mail me offline. Robert Rolls. **********************************************************************" This correspondence is for the named person's use only. It may contain confidential or legally privileged information or both. " No confidentiality or privilege is waived or lost by any " mistransmission. If you receive this correspondence in error, please immediately delete it from your system and notify the sender. You must not disclose, copy or rely on any part of this correspondence if you are not the intended recipient. Any views expressed in this message are those of the individual sender, except where the sender expressly, and with authority, states them to be the views of Vodafone. This email has been checked for viruses. ********************************************************************************************** You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced DOTNET, or subscribe to other DevelopMentor lists at http://discuss.develop.com.