2013-04-04 61 views
0

形成組件我有叫MSMQMessageThread方法,在Form1類包含C#訪問從

public void ExecuteMessageOperations(MSMQMessage MSMQ) 
    { 
     switch (MSMQ.MesType) 
     { 
      case "01": { label1.Text = MSMQ.MesContent; MessageBox.Show(MSMQ.MesContent); button1.Text = MSMQ.MesContent; }; 
       break; 
      case "02": 
       { 
        dataGridView1.Columns.Add("Data", "Data"); 
        dataGridView1.Rows.Add(MSMQ.MesContent); 

       }; 
       break; 
      case "03": 
       { 
        string[] separated = MSMQ.MesContent.Split(new Char[] { ',' }); 
        try 
        { 
         Rectangle rect = new Rectangle(Convert.ToInt16(separated[0]), 
          Convert.ToInt16(separated[1]), Convert.ToInt16(separated[2]), 
          Convert.ToInt16(separated[2])); 
         SolidBrush brush = new SolidBrush(XMLConfigs.GetBrushColor()); 
         Graphics Grph = pictureBox1.CreateGraphics(); 
         Grph.FillEllipse(brush, rect); 

        } 
        catch (Exception) 
        { 
         MessageBox.Show("Wrong parameters"); 
        }; 
       }; 
       break; 
     } 

和類,它包含了Form1的。這個類有方法

public void PerformOperations() 
    { 
     while (true) 
     { 
      try 
      { 
       Form1 f = new Form1(); 
       f.ExecuteMessageOperations(MSMQMessage.ReceiveMessage(@".\private$\TestQueue")); 
      } 
      catch (System.Messaging.MessageQueueException) { } 
     } 
    } 

代碼正常編譯,但方法ExecuteMessageOperations無能爲力。錯誤在哪裏,以及如何訪問方法ExecuteMessageOperations中的Form1組件? P.S.對不起,我的英語

+6

您是否試圖刪除'catch(System.Messaging.MessageQueueException){}'而不是默默吞下異常?可能是你的'MSMQMessage.ReceiveMessage'拋出異常,你忽略它在空的catch塊 – 2013-04-04 15:08:56

+0

不,它工作正常。那個嘗試站在那裏捕捉超時異常。 var message =(MSMQMessage)mq.Receive(TimeSpan.FromSeconds(1.0), MessageQueueTransactionType.Single).Body; – user2236515 2013-04-04 15:24:29

+0

好吧,「無所事事」是什麼意思?它沒有被調用,或者它沒有執行任何工作,所以沒有明顯的副作用?你能否至少試圖幫助我們解決你的問題。 – 2013-04-04 15:39:25

回答

0

把一個斷點放在你的switch語句和'step over'之間。讓我們知道它是否實際上首先調用方法。

+0

是的,它是調用方法。 MessageBox.Show(MSMQ.MesContent); 這段代碼是爲了測試而編寫的,它在每次消息到達時都在工作 – user2236515 2013-04-04 15:17:44