I saw this error on other posts, but not for this exact situation.
I have two classes that do the same with MessageQueue. Because of this, I distracted the creation and deletion of the queue to the helper class. I get this error and I don’t see how the queue can be deleted more than once.
The messageQueue object can be deleted more than once in the MsmqHelper.DisposeQueue (MessageQueue) method
In one of the classes it is used like this:
private MessageQueue _messageQueue;
Then in the constructor of the class:
this._messageQueue = MsmqHelper.InitializeQueue();
Not that it really mattered, but for completeness, the queue is used here:
this._messageQueue.Send(workflowCreated);
And here are the Dispose methods:
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
private void Dispose(bool disposing)
{
if (disposing == false) { return; }
MsmqHelper.DisposeQueue(this._messageQueue);
}
And this is the code in the helper class that actually calls Dispose ():
public static void DisposeQueue(MessageQueue messageQueue)
{
if (messageQueue != null)
{
messageQueue.Close();
messageQueue.Dispose();
messageQueue = null;
}
}
Where is it possible for a queue to be deleted more than once in this situation?
** Change **
, . , :
, . messageQueue (this._messageQueue) . , messageQueue null null, . - (this._messageQueue) . , .
, (this._messageQueue) null . MsmqHelper.DisposeQueue(). , ref DisposeQueue() .
** 2 **
. .
public static void DisposeQueue(ref MessageQueue messageQueue)
{
if (messageQueue == null) { return; }
messageQueue.Close();
messageQueue.Dispose();
messageQueue = null;
}
** 3 - ? **
, . messageQueue.Dispose(), . , messageQueue.Close() messageQueue.Dispose() . . , Close() Dispose() .