使用线程实现进度控制
我对 C 中的线程概念很陌生,所以我发现很难实现它 在我的职能中。我有一个简单的应用程序,我想在其中显示进度条 特定的地方。在一个特定的函数中,我将读取文件(在 for 循环中)进行一些操作(关于我的应用程序)。当它读取文件时,我想显示一个进度条,表明它正在读取文件。我知道应该使用线程的概念来完成,但我不太确定如何做到这一点。
I am new to the concept of threading in C, so I find it difficult to implement that
in my function. I have a simple application in which I want to display a progress bar at a
particular place. In a particular function I will read files(in a for loop) for some manipulations(regarding my application). While it's reading the files I want to display a progress bar, stating that it's in process of reading files. I know it should be done using the concept of threading, but I am not quite sure how to do it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在主程序中创建一个工作线程并设置执行文件处理的回调例程。
该例程还将计算完成的百分比。每当该百分比发生变化时,发布
值作为窗口消息,主线程将捕获并更新进度条控件。
您可以定义应用程序内部消息,例如
#define MSG_PROGRESS_VALUE (WM_USER + 1)
。编辑:样本,
Create a worker thread in the main program and set the callback routine that does the file processing.
That routine also will calculate the percentage that is completed. Whenever that percent changes, post the
value as a window message which the main thread will catch and update the progress bar control.
You can define application inner messages like
#define MSG_PROGRESS_VALUE (WM_USER + 1)
.Edit: sample,