C#每秒密码迭代次数 [英] C# Password iterations per second

查看:115
本文介绍了C#每秒密码迭代次数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中创建了Windows窗体应用程序,计算密码迭代
每秒但是当我点击开始按钮来计算速度它运行缓慢,它显示非常大的数字!如何解决这个问题?

 秒表st = new秒表(); 
st.Start();

while(st.Elapsed< TimeSpan.FromSeconds(1))
{
count ++;
}

SetControlPropertyThreadSafe(label23," Text",count.ToString()+" passwords / s");

解决方案

嗨Pavlex4,


>>当我点击开始按钮计算速度时,它运行缓慢


我在没有未知的情况下测试上面的代码

 SetControlPropertyThreadSafe(label23," Text",count.ToString()+" passwords / s"); 

而不是

 textBox1.Text = count.ToString(); 

结果是它每秒运行一次,因为你将
TimeSpan.FromSeconds 设置为1秒,所以运行速度不是很慢。因此,如果您的代码运行缓慢,可能由于
SetControlPropertyThreadSafe ,请检查它。


>>它显示非常大的数字!


来自
MSDN
我们可以获取有关 Stopwatch.Elapsed $ b $的信息b 属性:获取当前实例测量的总经过时间。


此外,我们还可以获取此信息:在典型的秒表场景中,您调用Start方法,然后最终调用Stop方法,然后使用Elapsed属性检查已用时间。


因此,如果你想使用 Stopwatch.Elapsed 属性,你应该使用Start方法和Stop方法,然后你可以测量经过的时间,但在你的代码中,只有Start方法而且没有Stop方法,所以编译器确实
不知道何时结束时间,然后你得到一个大的计数,计数是一秒钟内的周期数。


>>如何解决这个问题?


请正确使用Elapsed,如:

 private voi d button1_Click(object sender,EventArgs e)
{
秒表stopWatch = new秒表();
stopWatch.Start();
Thread.Sleep(1000);
stopWatch.Stop();
//将经过的时间作为TimeSpan值获取。
TimeSpan ts = stopWatch.Elapsed;

//格式化并显示TimeSpan值。
string elapsedTime = String.Format(" {0:00}:{1:00}:{2:00}。{3:00}",
ts.Hours,ts.Minutes ,ts.Seconds,
ts.Milliseconds / 10);
textBox2.Text = elapsedTime.ToString();
}

希望这会有所帮助!


最好的问候,


Stanly


I have created windows form application in C# which calculates password iterations per second but When I click start button to calculate speed it runs slow and it shows very big numbers!How to fix this issue?

Stopwatch st = new Stopwatch();
st.Start();

while (st.Elapsed < TimeSpan.FromSeconds(1))
{
    count++; 
}

SetControlPropertyThreadSafe(label23, "Text", count.ToString() + " passwords/s");

解决方案

Hi Pavlex4,

>>When I click start button to calculate speed it runs slow

I test the above code without the unknown

SetControlPropertyThreadSafe(label23, "Text", count.ToString() + " passwords/s");

instead of

textBox1.Text = count.ToString();

The result is that it runs once every second, it did not run very slowly because you set the TimeSpan.FromSeconds to one second. So if your code runs slowly, there may due to the SetControlPropertyThreadSafe, please check it.

>>and it shows very big numbers!

From the MSDN we can get the information about Stopwatch.Elapsed Property: Gets the total elapsed time measured by the current instance.

Also we can get this information: In a typical Stopwatch scenario, you call the Start method, then eventually call the Stop method, and then you check elapsed time using the Elapsed property.

So if you want to use the Stopwatch.Elapsed property, you should use the Start method and Stop method, then you can measure the elapsed time, but in your code, there is only Start method and no Stop method, so the compiler does not know when to end the timing, then you get a large count, the count is the number of cycles within a second.

>>How to fix this issue?

Please use the Elapsed correctly, just like:

        private void button1_Click(object sender, EventArgs e)
        {
            Stopwatch stopWatch = new Stopwatch();
            stopWatch.Start();
            Thread.Sleep(1000);
            stopWatch.Stop();
            // Get the elapsed time as a TimeSpan value.
            TimeSpan ts = stopWatch.Elapsed;

            // Format and display the TimeSpan value.
            string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                ts.Hours, ts.Minutes, ts.Seconds,
                ts.Milliseconds / 10);
            textBox2.Text = elapsedTime.ToString();
        }

Hope this helps!

Best Regards,

Stanly


这篇关于C#每秒密码迭代次数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆