2017-08-28 40 views
0

有接收信件的功能:的的IMail對象轉移到另一種形式

private void button1_Click(object sender, EventArgs e) 
     {   
      ListViewItem list = new ListViewItem("Messages"); 
      using (imap = new Imap()) 
      { 
       imap.ConnectSSL("imap.yandex.ru"); 
       imap.Login("----", "---"); 
       imap.SelectInbox(); 
       List<long> uids = imap.SearchFlag(Flag.All); 
       IMail email; 
       listView1.Items.Clear(); 
       foreach (long uid in uids) 
       { 
        ListViewItem lvi = new ListViewItem(); 
        email = new MailBuilder().CreateFromEml(imap.GetMessageByUID(uid));     
        lvi.SubItems.Add(email.Subject); 
        listView1.Items.Add(lvi); 
       } 
      } 
     } 

另一種形式,我試圖傳遞給IMAIL objecto oher形式:

private void button2_Click(object sender, System.EventArgs e) 
    {//тут надо пулучать выбранный UID 

     //получим выделенный элемент 
     int SelectedMessageIndex = listView1.FocusedItem.Index; 
     IMail email2 = new MailBuilder().CreateFromEml(imap.GetMessageByUID(SelectedMessageIndex)); 
     MessageForm messageForm = new MessageForm(SelectedMessageIndex,email2); //нужно передать нужный email 
     messageForm.ShowDialog(); 

    } 

但我得到的錯誤:

Access to the liquidated object is not possible. Object name: "ClientBase".

回答

0

它看起來像你的imap變量是一個類成員。問題在於:

using (imap = new Imap()) 

...在button1_Click()。當using()代碼塊結束時,您的imap對象被處置。當您嘗試在button2_Click()中再次使用它時,它已經消失。您需要在button2_Click()中不處理對象或創建新的imap對象。

相關問題