相关疑难解决方法(0)

Socket.Poll在不同的机器上有很大的变化

我有一个继承的.net 2.0客户端应用程序使用套接字.服务器正在iSeries上运行.我有计算机试图使用客户端应用程序,并遇到滞后.在经历"滞后"的计算机上,我已经确定Socket.Poll方法需要更长的时间.

以下是我认识的(我认为).

MyApp.WriteLogEntry("CS: START check for readable socket");
start = DateTime.Now;
readable = ControllerSocket.Poll(500, SelectMode.SelectRead);
end = DateTime.Now;
MyApp.WriteLogEntry("CS: END check for readable socket");
elapsed = end.Subtract(start);
MyApp.WriteLogEntry("Elapsed TotalMilliseconds = " + elapsed.TotalMilliseconds.ToString());  
Run Code Online (Sandbox Code Playgroud)

从没有滞后的计算机登录

10.04.22.994427|CS: START check for readable socket
10.04.22.997427|CS: END check for readable socket
10.04.22.997427|Elapsed TotalMilliseconds = 1.0001
Run Code Online (Sandbox Code Playgroud)

从滞后的计算机登录

10.03.30.729816|CS: START check for readable socket
10.03.30.745432|CS: END check for readable socket
10.03.30.745432|Elapsed TotalMilliseconds = 15.6152
Run Code Online (Sandbox Code Playgroud)

两台计算机都是Windows 7 64位.一个是来自磁盘的新副本(没有延迟),其他计算机是企业形象(滞后).两台计算机都是千兆以太网.

我在两者上都禁用了防火墙,它们都运行Symantec Endpoint 12,配置相同.我已经一起删除了SEP并得到了相同的结果

为何延误?注册表设置?Ninja Gremlins?

EDIT切换到使用秒表类进行计时

MyApp.WriteLogEntry("CS: START check …
Run Code Online (Sandbox Code Playgroud)

.net sockets

4
推荐指数
1
解决办法
417
查看次数

尽管timeBeginPeriod(1),为什么最小Threading.Timer间隔15ms

以下代码段

    [DllImport("winmm.dll", EntryPoint = "timeBeginPeriod")]
    public static extern uint TimeBeginPeriod(uint uMilliseconds);

    static void Main(string[] args)
    {
        if (TimeBeginPeriod(1) != 0)
            Console.WriteLine("TimeBeginPeriod failed!");

        Console.WriteLine("Sleep");
        Stopwatch sw = Stopwatch.StartNew();
        for (int i = 0; i < 10; i++)
        {
            Thread.Sleep(1);
            Console.WriteLine(sw.ElapsedTicks * 1000d / Stopwatch.Frequency);
            sw.Restart();
        }

        Console.WriteLine("Threading.Timer");
        sw = null;
        System.Threading.Timer t = null;
        int n = 0;

        t = new Timer(state =>
        {
            if (sw == null)
                sw = Stopwatch.StartNew();
            else
            {
                Console.WriteLine(sw.ElapsedTicks * 1000d / Stopwatch.Frequency);
                n++;
                sw.Restart();
            } …
Run Code Online (Sandbox Code Playgroud)

.net sleep timer

3
推荐指数
1
解决办法
1444
查看次数

为什么在Windows上没有具有microsec分辨率的boost :: date_time?

Win32系统boost::date_time::microsec_clock()上实现使用ftime,它只提供毫秒分辨率:链接到doc

Stackoverflow上有一些问题/答案说明这一点并链接文档,但没有解释为什么会这样:

似乎有办法在Windows上实现微秒分辨率:

我感兴趣的是为什么Boost以这种方式实现它,反过来又有可能解决方案更合适?

c++ windows time boost boost-date-time

3
推荐指数
1
解决办法
597
查看次数

tkinter - 形状不均匀,动画看起来很糟糕

今天开始玩python的tkinter并遇到了一些问题.我创建了一个动画,以给定的速度在屏幕上移动球.(当它击中屏幕时,它会返回)

  1. 为什么我的球看起来很糟糕?它的形状不均匀?(它像眨眼一样)

  2. 有没有更好的方法呢?

代码:

from tkinter import *
import time

WIDTH = 800
HEIGHT = 500
SIZE = 100
tk = Tk()
canvas = Canvas(tk, width=WIDTH, height=HEIGHT, bg="grey")
canvas.pack()
color = 'black'


class Ball:
    def __init__(self):
        self.shape = canvas.create_oval(0, 0, SIZE, SIZE, fill=color)
        self.speedx = 3
        self.speedy = 3

    def update(self):
        canvas.move(self.shape, self.speedx, self.speedy)
        pos = canvas.coords(self.shape)
        if pos[2] >= WIDTH or pos[0] <= 0:
            self.speedx *= -1
        if pos[3] >= HEIGHT or pos[1] <= 0:
            self.speedy *= -1

ball …
Run Code Online (Sandbox Code Playgroud)

python tkinter

3
推荐指数
1
解决办法
448
查看次数

为什么 time.Now().UnixNano() 在 IO 操作后返回相同的结果?

time.Now().UnixNano()用来计算我的代码的某些部分的执行时间,但我发现了一件有趣的事情。IO 操作后经过的时间有时为零!它出什么问题了?

代码在 Go 1.11 中运行,并使用标准库"time". Redis 库是"github.com/mediocregopher/radix.v2/redis". redis 服务器版本为 3.2。我在 Windows 上使用 VSCode 编辑器运行它。

isGatherTimeStat = false
if rand.Intn(100) < globalConfig.TimeStatProbability { // Here I set TimeStatProbability 100
    isGatherTimeStat = true
}
if isGatherTimeStat {
    timestampNano = time.Now()
}
globalLogger.Info("time %d", time.Now().UnixNano())
resp := t.redisConn.Cmd("llen", "log_system")
globalLogger.Info("time %d", time.Now().UnixNano())
if isGatherTimeStat {
    currentTimeStat.time = time.Since(timestampNano).Nanoseconds()
    currentTimeStat.name = "redis_llen"
    globalLogger.Info("redis_llen time sub == %d", currentTimeStat.time)
    select {
    case t.chTimeStat <- currentTimeStat:
    default:
    }
} …
Run Code Online (Sandbox Code Playgroud)

windows time go

3
推荐指数
1
解决办法
449
查看次数

标签 统计

.net ×2

time ×2

windows ×2

boost ×1

boost-date-time ×1

c++ ×1

go ×1

python ×1

sleep ×1

sockets ×1

timer ×1

tkinter ×1