c# - Can not get MSMQ Com to find my Queue -
i trying count of messages in msmq. have found code on internet (many times):
// setup queue management com stuff msmqmanagement _queuemanager = new msmqmanagement(); object machine = "mylaptopcomputer"; object path = @"direct=os:mylaptopcomputer\private$\myqueue"; _queuemanager.init(ref machine, ref path); console.writeline(_queuemanager.messagecount); marshal.releasecomobject(_queuemanager);
every time _queuemanager.init
fails error:
the queue path name specified invalid.
i have checked (and double checked) queue name see if wrong. have tried different queues, different machines, running remote, running local... nothing works.
i have tried variations on code above. example have tried:
_queuemanager.init("mylaptopcomputer", @"direct=os:mylaptopcomputer\private$\myqueue");
the queues used nservicebus , function fine when use nservicebus access them.
does have idea on how can work?
i think problem error you're getting little misguiding. msmqmanagement.init
takes 3 parameters. they're optional why in other languages (like vb) you'll see called 2 parameters.
there codeproject project shows how you're doing in c#:
private int getmessagecount(string queuename) { int count = 0; try { msmq.msmqmanagement mgmt = new msmq.msmqmanagement(); msmq.msmqoutgoingqueuemanagement outgoing; string s = "yourpcname"; object ss = (object)s; string pathname = queuename; object pn = (object)pathname; string format = null; object f = (object)format; mgmt.init(ref ss , ref f, ref pn); outgoing = (msmq.msmqoutgoingqueuemanagement)mgmt; count = outgoing.messagecount; } catch (exception ee) { messagebox.show(ee.tostring()); } return count; }
it might provide better starting point.
Comments
Post a Comment