我想讀取MSMQ,其中隊列數據的字節數和排隊隊列數在1分鐘內產生的1500左右。所以如果連續讀取隊列cpu將繼續執行30%。並在一段時間後停止。我需要閱讀高達4小時的高容量隊列。 所以我想要安全線程閱讀的方式,不應該阻止。 其實我也不好對線程,因此你可以請幫我..想在c#中使用安全線程快速讀取msmq消息.net
目前我以這種方式正在讀
bool ProcessStatus; //process
Thread _UDPthreadConsme;
private void btn_receive_Click(object sender, EventArgs e)
{
if (MessageQueue.Exists(@".\private$\myquelocal"))
{
ThreadStart _processrcs = new ThreadStart(receivemessages);
_UDPthreadConsme = new Thread(_processrcs);
ProcessStatus = true;
_UDPthreadConsme.Start();
}
}
private void receivemessages()
{
MessageBox.Show("Start");
while (ProcessStatus)
{
try
{
// Connect to the a queue on the local computer.
MessageQueue myQueue = new MessageQueue(@".\private$\myquelocal");
System.Messaging.Message[] myMessagecount = myQueue.GetAllMessages();
if (myMessagecount.Length <= 0)
return;
myQueue.Formatter = new BinaryMessageFormatter();
// Receive and format the message.
System.Messaging.Message myMessage = myQueue.Receive();
byte[] buffer = (byte[])myMessage.Body;
// here i convert buffer to its related structure and then insert the values in database sqlserver.
}
}
嗯。 halv klass? – jgauffin 2011-03-11 12:42:24
忍者移動並意外擊中提交按鈕! ;-) – 2011-03-11 12:47:09