At one point in my code, i subscribe to the following event :-
UploadFolderMessageQueue.ReceiveCompleted += UploadMSMQReceiveCompleted;
works great and when the Message Queue’s Recieved Completed event fires, my delegate handles it.
Now, I’m wanting to CHECK to see if the event has been subscribed to, before I subscribe to it. I get an compile time error when I do :-
// Compile Time Errors...
if (UploadFolderMessageQueue.ReceiveCompleted == null)
{
UploadFolderMessageQueue.ReceiveCompleted += UploadMSMQReceiveCompleted;
UploadFolderMessageQueue.Formatter =
new XmlMessageFormatter(new[] {typeof (string)});
}
The event
‘System.Messaging.MessageQueue.ReceiveCompleted’
can only appear on the left hand side
of += or -=
I know this is embarrassingly simple .. but I’m stumped 🙁 Any suggestions?
you cannot do this from subscriber to the event. Only publisher can check if there are any subscribers. You will need to keep track of subscription using some other mechanism in your class like:
then you can use this: