如何让我的程序在计算过程中不冻结? [英] How do I make my program not freeze during calculs ?

查看:57
本文介绍了如何让我的程序在计算过程中不冻结?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



所以我重复这段代码10次。

如何让我的程序不冻结,而是开始漂亮的进度条。

不知道我是否明确表示抱歉:)



我尝试过:



Hi,
So I repeat this code 10 times.
How can I make my program not freeze but instead a pretty progressbar starts.
Don't know if i'm clear sorry :)

What I have tried:

percent_wins = (Double.Parse(string) / (Double.Parse(string) + Double.Parse(string))) * 100;

推荐答案

说实话,那些代码 - 甚至做了十次 - 在UI方面甚至不应该引人注意,并且可能会被单独加速因为任务处理的开销可能会超过所需的处理时间。



所以首先看看你有什么以及它有多长你正在服用:秒表课程 [ ^ ]就是为这种东西而设计的,所以用你的代码自己解释你的代码,并找出实际花费的时间,以及在哪里。当你知道这一点时,你有一个指标可以开始改进 - 但是直到你有了它,你只是猜测这就是这个,必须并且很有可能你错了!
To be honest, that code - even done ten times - shouldn't even really be noticeable in terms of the UI, and probably can;t be individually speeded up much as the overhead of task processing will probably exceed the processing time required.

So start by looking at what you have and how long it's actually taking: Stopwatch class[^] is designed for this kind of thing, so "pepper" your code liberaly with tem, and find out how much time it's actually taking, and where. When you know that, you have a metric to start improving things from - but until you have that, you are just guessing that "it's this bit, gotta be" and there is a good chance you are very wrong!


Quote:

如何让我的程序在计算过程中不冻结?

How do I make my program not freeze during calculs ?



1解决方案是显着优化代码。


1 Solution is to optimize dramatically that code.

percent_wins = (Double.Parse(string) / (Double.Parse(string) + Double.Parse(string))) * 100;






To

WhatEver = (Double.Parse(string);
percent_wins = (WhatEver / (WhatEver + WhatEver)) * 100;



然后到


Then to

WhatEver = (Double.Parse(string);
percent_wins = (WhatEver / (2 * WhatEver)) * 100;



然后到


Then to

WhatEver = (Double.Parse(string);
percent_wins = (1 / 2 ) * 100;



然后到


Then to

percent_wins = 100 / 2;



然后到


Then to

percent_wins = 50;



这正是你的代码行所做的。它不应该再冻结。


This is exactly what your line of code is doing. It shouldn't freeze anymore.


读这个:使用C#中的乘法移位优化整数除法 [ ^ ] ...
Reading this : Optimizing integer divisions with Multiply Shift in C#[^] ...


这篇关于如何让我的程序在计算过程中不冻结?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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