2017-10-17 89 views
-2

我一直在为这个项目工作,而messagebox没有显示 有人可以帮我吗?C#MessageBox不能正常工作

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using MaterialSkin.Controls; 
using MaterialSkin.Animations; 
using MaterialSkin; 
using System.Web; 
using System.Net; 
using System.IO; 
using System.Management; 
using System.Windows; 

namespace Liquid_Reborn 
{ 
    public partial class Login : MaterialForm 
    { 
     public Login() 
     { 
      InitializeComponent(); 

      var materialSkinManager = MaterialSkinManager.Instance; 
      materialSkinManager.AddFormToManage(this); 
      materialSkinManager.Theme = MaterialSkinManager.Themes.LIGHT; 
      materialSkinManager.ColorScheme = new ColorScheme(Primary.LightBlue200, Primary.LightBlue300, Primary.LightBlue300, Accent.LightBlue200, TextShade.WHITE); 

     } 

     private void Form1_Load(object sender, EventArgs e) 
     { 
      string cpuInfo = string.Empty; 
      ManagementClass mc = new ManagementClass("win32_processor"); 
      ManagementObjectCollection moc = mc.GetInstances(); 
      foreach (ManagementObject mo in moc) 
      { 
       if (cpuInfo == "") 
       { 
        //Get only the first CPU's ID 
        cpuInfo = mo.Properties["processorID"].Value.ToString(); 
        break; 
       } 
       var plainTextBytes = Encoding.UTF8.GetBytes(cpuInfo); 
       String hwid = Convert.ToBase64String(plainTextBytes); 
       WebClient client = new WebClient(); 
       Stream stream = client.OpenRead("http://techshow.us/liquid/hwid.txt/"); 
       StreamReader reader = new StreamReader(stream); 
       String content = reader.ReadToEnd(); 
       if (content.Contains(hwid)) 
       { 

       } 
       MessageBox.Show("ok"); 

      } 
     } 
    } 
} 

为什么不显示消息框? 香港专业教育学院尝试的大多数事情,没有工作 什么也没有发生在用户界面只显示和IDK的做什么\ 请帮助我,我需要为我的项目

+0

集合'moc'可能是空的,这就是为什么循环不执行 – shahsani

+0

你是什么意思?该代码不在集合中 –

+0

您是否在线上放置了一个调试点来检查它是否正在执行? – TejSoft

回答

1

if (cpuInfo == "")将永远是正确的,因为值没有初始化后更改。在到达MessageBox代码之前,循环会中断。

删除break;允许代码继续,或

使用continue;而是跳到循环中的下一个值。