Scrolling the scrollbar of a ConsoleApplication hangs the thread

白昼怎懂夜的黑 提交于 2019-12-11 06:37:30

问题


I've got some server apps that I've been trying to get some metrics from so I can debug them. I found that when scrolling back up the window I'd suddenly get timeouts from the clients. Sure enough, moving the scrollbar stopped the application.

I'm probably missing something fundemental here, but I can't work out why moving the scrollbar on a Console window would block the thread.

It's very simple to reproduce:

Sub Main()
    Do
        Console.WriteLine(Now.ToString("O"))
        System.Threading.Thread.Sleep(1000)
    Loop
End Sub

Run that up, and any interaction with the window blocks the thread. In the example below, I just moved the scrollbar a bit and held it in position for a few seconds before releasing

http://www.briandrought.com/miscpics/scrollbar.png

I've tried it with a Timer type loop rather than a Thread.Sleep but the same issue appears. What am I doing wrong (other than not using a service instead!)?

Kind Regards,

Brian


回答1:


You're not doing anything wrong. That's just how windows console apps behave. In normal operation your server apps would surely run as headless services so there should be no issue in production.



来源:https://stackoverflow.com/questions/6143628/scrolling-the-scrollbar-of-a-consoleapplication-hangs-the-thread

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