本文介绍了从while循环调用线程时,Windows窗体GUI被冻结.如何使Gui做出响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class ...
{
   onClick()
   {
      while(true)
      {
        //call the thread from here
        threadpool(request)//send request to thread using thread pool
      }
   }

   //the function for thread
   threadfunction()//function that thread calls
   {

   // I am not able to change the textbox/datagridview in windowsform from here the main ui gets stuck //

   }
}

我不想更改上述逻辑,因为有可能因为我的程序被卡住而从线程的函数同时更新datagrid.

I dont want to change the above logic is it possible to update datagrid simaltaneously from function for thread because my program just get stuck.

推荐答案

while (true)应该在线程函数内,而不在onClick中.否则,GUI会卡住,因为它不断执行while(true).

The while (true) should be inside the threadfunction, not in the onClick. Otherwise the GUI gets stuck because it's executing endlessly the while(true).

这篇关于从while循环调用线程时,Windows窗体GUI被冻结.如何使Gui做出响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-01 16:42