private void buttonMD5Sure_Click(object sender, EventArgs e) { this.textBoxMD5Str.Text = string.Empty; bool fsChecked = false; bool strChecked = false; switch (comboBoxMD5.SelectedItem.ToString()) { case "文件": fsChecked = true; break; default: strChecked = true; break; } if (strChecked) { string change = this.textBoxFileStr.Text.Trim(); if (!string.IsNullOrEmpty(change)) { this.textBoxMD5Str.Text = MD5Utils.GetMD5String(change); } else { MessageBox.Show("Exchange Text can't null or empty.", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (fsChecked) { string m_MD5SelectFilePath = this.textBoxFilePath.Text; if (File.Exists(m_MD5SelectFilePath)) { if (m_MD5ExchargeThread == null || m_MD5ExchargeThread.ThreadState != ThreadState.Running) { m_MD5ExchargeThread = null; m_MD5ExchargeThread = new Thread(() => { using (FileStream fsStream = new FileStream(m_MD5SelectFilePath, FileMode.Open, FileAccess.Read)) { long length = fsStream.Length; byte[] bs = new byte[length]; int r = fsStream.Read(bs, 0, bs.Length); string md5Str = MD5Utils.GetMD5String(bs); if (!string.IsNullOrEmpty(md5Str)) { this.textBoxMD5Str.Text = md5Str; } else { MessageBox.Show("Exchange File String is null.", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }); m_MD5ExchargeThread.SetApartmentState(ApartmentState.STA); m_MD5ExchargeThread.Start(); } } else { MessageBox.Show("Exchange MD5 Select File not exist.", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Exchange Check Box don't select.", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error); } }