我写了一些代码来测试try-catch的影响,但看到了一些令人惊讶的结果.
static void Main(string[] args)
{
Thread.CurrentThread.Priority = ThreadPriority.Highest;
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime;
long start = 0, stop = 0, elapsed = 0;
double avg = 0.0;
long temp = Fibo(1);
for (int i = 1; i < 100000000; i++)
{
start = Stopwatch.GetTimestamp();
temp = Fibo(100);
stop = Stopwatch.GetTimestamp();
elapsed = stop - start;
avg = avg + ((double)elapsed - avg) / i;
}
Console.WriteLine("Elapsed: " + avg);
Console.ReadKey();
}
static long Fibo(int n)
{
long n1 = 0, n2 …Run Code Online (Sandbox Code Playgroud) 我正在用C#编写一个需要重复访问1个图像文件的程序.大部分时间它都可以工作,但如果我的计算机运行速度很快,它会在将文件保存回文件系统之前尝试访问该文件并抛出错误:"另一个进程正在使用的文件".
我想找到解决这个问题的方法,但是我所有的谷歌搜索都只是通过使用异常处理来创建检查.这违背了我的宗教信仰,所以我想知道是否有人有更好的方法呢?
我在汇编过程中有一个任务来计算字符串中的单词数,我需要将我的答案保存在cx寄存器中.(我正在使用80x86处理器)
所以我设定:
cx为0 - 这将是我的计数器
bx为0 - 这将是我的索引
我想知道我是否正确使用它,这是我的代码:
.model small
.stack 100h
.data
A db ' this is a test $'
B db 100 dup('$')
.code
mov ax, @data
mov ds, ax
mov cx, 0
mov bx, 0
looping:
cmp A[bx], ' '
jne foundchar
inc bx
jmp looping
foundchar:
inc bx
cmp A[bx], ' '
je foundword
cmp A[bx], '$'
je soff
jmp foundchar
foundword:
inc cx
inc bx
jmp looping
soff:
.exit
end
Run Code Online (Sandbox Code Playgroud)
而我班上的其他人也采用了不同的方式,她将si设置为A的偏移...我并不真正理解这个解决方案:
mov cx,0
mov …Run Code Online (Sandbox Code Playgroud)