コード例 #1
0
        /// <summary>
        /// 重新加密
        /// </summary>
        public void ReEncrypt()
        {
            Thread thread = new Thread(new ParameterizedThreadStart(delegate(object obj)
            {
                try
                {
                    InvokeDelegate invokeDelegate = delegate()
                    {
                        pbDir.Value             = 0;
                        lblProgressDir.Text     = "0%";
                        pbFile.Value            = 0;
                        lblProgressFile.Text    = "0%";
                        pbDir.Visible           = true;
                        lblProgressDir.Visible  = true;
                        pbFile.Visible          = false;
                        lblProgressFile.Visible = false;
                        lblShowPath.Text        = "加密文件夹:" + Application.StartupPath;
                        lblShowPath.Visible     = true;
                        DisableBtns();
                    };
                    InvokeUtil.Invoke(this, invokeDelegate);
                    DateTime t1 = DateTime.Now;
                    DirectoryEncrypt.EncryptCurrentDirectory(Application.StartupPath, txtPwd.Text, RefreshDirProgress, RefreshFileProgress);
                    DateTime t2 = DateTime.Now;
                    string t    = t2.Subtract(t1).TotalSeconds.ToString("0.00");
                    if (MessageBox.Show("加密成功,耗时" + t + "秒", "提示") == DialogResult.OK)
                    {
                        invokeDelegate = delegate()
                        {
                            EnableBtns();
                            Application.Exit(); //加密成功后关闭程序
                        };
                        InvokeUtil.Invoke(this, invokeDelegate);
                    }
                }
                catch (Exception ex)
                {
                    if (MessageBox.Show("加密失败:" + ex.Message, "提示") == DialogResult.OK)
                    {
                        InvokeDelegate invokeDelegate = delegate()
                        {
                            EnableBtns();
                        };
                        InvokeUtil.Invoke(this, invokeDelegate);
                    }
                }
            }));

            thread.Start();
        }
コード例 #2
0
        private void btnEncryptThis_Click(object sender, EventArgs e)
        {
            #region 验证
            if (txtPwd.Text == "")
            {
                MessageBox.Show("密码不能为空", "提示");
                return;
            }

            if (txtPwdCfm.Text == "")
            {
                MessageBox.Show("xwuser密码不能为空", "提示");
                return;
            }
            #endregion

            if (MessageBox.Show(string.Format("确定加密当前文件夹?"),
                                "提示", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
            {
                return;
            }

            Thread thread = new Thread(new ParameterizedThreadStart(delegate(object obj)
            {
                try
                {
                    InvokeDelegate invokeDelegate = delegate()
                    {
                        pbDir.Value             = 0;
                        lblProgressDir.Text     = "0%";
                        pbFile.Value            = 0;
                        lblProgressFile.Text    = "0%";
                        pbDir.Visible           = true;
                        lblProgressDir.Visible  = true;
                        pbFile.Visible          = false;
                        lblProgressFile.Visible = false;
                        lblShowPath.Text        = "加密文件夹:" + Application.StartupPath;
                        lblShowPath.Visible     = true;
                        DisableBtns();
                    };
                    InvokeUtil.Invoke(this, invokeDelegate);
                    DateTime t1 = DateTime.Now;
                    DirectoryEncrypt.EncryptCurrentDirectory(Application.StartupPath, txtPwd.Text, RefreshDirProgress, RefreshFileProgress);
                    DateTime t2 = DateTime.Now;
                    string t    = t2.Subtract(t1).TotalSeconds.ToString("0.00");
                    if (MessageBox.Show("加密成功,耗时" + t + "秒", "提示") == DialogResult.OK)
                    {
                        invokeDelegate = delegate()
                        {
                            EnableBtns();
                            Application.Exit(); //加密成功后关闭程序
                        };
                        InvokeUtil.Invoke(this, invokeDelegate);
                    }
                }
                catch (Exception ex)
                {
                    if (MessageBox.Show("加密失败:" + ex.Message, "提示") == DialogResult.OK)
                    {
                        InvokeDelegate invokeDelegate = delegate()
                        {
                            EnableBtns();
                        };
                        InvokeUtil.Invoke(this, invokeDelegate);
                    }
                }
            }));
            thread.Start();
        }