C# - Debug.WriteLine - is this function ASync?

谁都会走 提交于 2019-12-11 02:49:37

问题


I just came across a situation: I was debugging a thread which iterates through a large amount of data. I was using Debug.WriteLine to print which record is being processed. What just happened is that thread has reported that it has processed all records, however, Visual Studio's debug window is still displaying out. I am positive that thread has completed its job.

Is Debug.WriteLine Async or data has been stacked in Visual Studio's buffer and is getting displayed slowly?


回答1:


MS does not mention this method as being async. The Debug.WriteLine method operates on the trace listeners and the phenomena you are seeing is a result of the implementation of the trace listener and not the Debug.WriteLine.

In general output is flushed to the screen when a buffer is full or after a timeout and not as it happens. This means that you should expect the output to be synchronous but delayed.




回答2:


Visual Studio is doing the async part. The Win32 API OutputDebugString does the same thing in Visual Studio's output window.

You could try using DebugView instead.



来源:https://stackoverflow.com/questions/2264578/c-sharp-debug-writeline-is-this-function-async

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!