Tag: 计时

为什么GetThreadTimes会返回

我正在尝试测量线程在进度报告中花费的时间,但是我从GetThreadTimes系统调用得到了非常奇怪的结果。 鉴于以下程序(在VS 2013中编译,以.NET 4.5为目标): using System; using System.Diagnostics; using System.Runtime.InteropServices; using System.Threading; namespace ThreadTimingTest { class Program { static Stopwatch _wallClockTimer; static System.Timers.Timer _timer = new System.Timers.Timer(); private static Thread _thread; private static IntPtr _threadHandle; static void Main(string[] args) { _timer = new System.Timers.Timer(); _timer.Elapsed += (s, e) => { System.Runtime.InteropServices.ComTypes.FILETIME start, end, rawKernelTime, rawUserTime; […]

精确测量线程中代码的执行时间(C#)

我正在尝试在多个线程上尽可能准确地测量某些代码位的执行时间,同时考虑上下文切换和线程停机时间。 该应用程序在C#(VS 2008)中实现。 例: public void ThreadFunc () { // Some code here // Critical block #1 begins here long lTimestamp1 = Stopwatch.GetTimestamp (); CallComplex3rdPartyFunc (); // A long lTimestamp2 = Stopwatch.GetTimestamp (); // Critical block #1 ends here // Some code here // Critical block #2 begins here long lTimestamp3 = Stopwatch.GetTimestamp (); CallOtherComplex3rdPartyFunc […]

C#app将C ++ dll通过回调返回到C#app

我正在编写一个调用C ++ DLL的C#应用​​程序。 这个dll是成像系统的设备驱动程序; 当获取图像时,可以从库中逐行地获得图像的预览。 C ++ dll采用回调来填充预览,该回调基本上由最终图像的大小,当前扫描的行和数据本身组成。 问题是,从扫描停止和C#回调停止获取信息时起,存在相当严重的延迟。 该程序的流程如下: 从C#中分配回调到C ++ dll 用户开始获取数据 设备启动 几秒后dll开始调用回调(正常) 设备完成图像形成 dll仍在调用回调的时间是图像形成的两倍。 这个dll适用于C ++应用程序就好了; 似乎没有最后一步延迟。 但是,在C#中,如果我立即返回回调,则延迟仍然存在; 无论我在回调中做什么,它都在那里。 这种延迟是否是从非托管代码调用托管代码的固有限制,或者是否有任何一方可以做到这一点以使其更快? 我与C ++库编写器有联系,因此可以从C ++端实现修复。 编辑:可以做一些像命名管道一样简单的工作吗? 应用程序可以从自己的管道中读取吗?