检测线程何时关闭(Detecting when thread has been closed)
在我的
C#
应用程序中,我有一个单独的窗口,其中包含一个在单独的线程中运行的进度条。 每隔30秒,它会从服务器发送数据请求并相应地填充进度条。问题是,当我关闭主程序时,带有进度条的第二个窗口保持打开状态。
如何编写第二个线程以检测第一个线程何时关闭,并相应地关闭它自己?
In my
C#
application, I have a separate window containing a progress bar that runs in a separate thread. Every 30 seconds it sends a request for data from a server and fills the progress bar accordingly.The problem is, when I close the main program, the second window with the progress bar stays open.
How can I program the second thread to detect when the first thread has been closed, and close itself accordingly?
原文:https://stackoverflow.com/questions/15838077
满意答案
是的,您拥有的代码将复制指针,而不是复制指针。 你需要复制每个子
model3
的内容,以及它们的子model3
(model3
,model2
,model3
,你没有提供定义。所以类似的东西(如果model1
等只是double [])...parameters current; double checkem[MAX_PARS]; double *p = &checkem[0]; // copy X into checkem memcpy(p, ¤t.x, numx * sizeof(struct model1)); p += (numx * sizeof(struct model1)) / sizeof(double); // copy Y into checkem after X memcpy(p, ¤t.y, numy * sizeof(struct model2)); p += (numy * sizeof(struct model2)) / sizeof(double); // copy Z into checkem after Y memcpy(p, ¤t.z, numz * sizeof(struct model3));
如果
model3
,model2
和model3
比双精度数组更复杂,则需要分别复制双精度数。请注意,代码未经测试,但应该为您提供引导。
Yes, the code you have will copy the pointers, not the
double
s. You need to copy the contents of each subarray, and their subarrays (model1
,model2
,model3
which you don't provide the definitions of. So something like (ifmodel1
etc are just double[]) ...parameters current; double checkem[MAX_PARS]; double *p = &checkem[0]; // copy X into checkem memcpy(p, ¤t.x, numx * sizeof(struct model1)); p += (numx * sizeof(struct model1)) / sizeof(double); // copy Y into checkem after X memcpy(p, ¤t.y, numy * sizeof(struct model2)); p += (numy * sizeof(struct model2)) / sizeof(double); // copy Z into checkem after Y memcpy(p, ¤t.z, numz * sizeof(struct model3));
If
model1
,model2
andmodel3
are more complex than an array of doubles, you'll need to copy the doubles separately.Note the code is untested, but should give you a steer.
相关问答
更多如何在c ++中引用动态分配的字符数组(How to reference a dynamically allocated character array in c++)
结构数组中的动态分配内存(C中)(Dynamically Allocated Memory in Structure Array (in C))
将.txt文件传输到malloc分配的动态内存(Transfer .txt file to dynamic memory allocated by malloc)
在动态分配的结构中初始化动态分配的结构(Initialize dynamically allocated structures within dynamically allocated structures)
在VS 2010中调试时如何查看动态分配的数组的内容?(How to see what are the contents of dynamically allocated array while debugging in VS 2010?)
C - 构建动态分配的指针数组,指向填充了文件输入的结构(C - Build dynamically allocated array of pointers to structures filled with input from file)
在C中删除动态分配的数组成员(Deleting dynamically allocated array members in C)
交换动态分配的结构(Swapping Dynamic allocated structures)
如何将动态分配的双精度结构和子结构的内容传输到数组?(How does one transfer the contents of dynamically allocated structures and substructures of doubles to an array? (C))
从C中的函数返回动态分配的结构数组?(Returning a dynamically allocated array of structures from a function in C?)
相关文章
更多线程报错 thread
引入thread后socket接受不了报文了
关于Thread类中的start()方法和run()方法
There is already an open DataReader associated with this Connection which must be closed first
一步一步掌握java的线程机制(二)----Thread的生命周期
org.apache.zookeeper.server.NIOServerCnxn - Thread Thread[main,5,main] died java.lang.NoSuchFieldError: AuthFailed
关于线程
为什么执行JAVA程序时,会出现Exception in thread"main" java.lan
action 线程问题。
多线程问题
最新问答
更多获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
如何通过引用返回对象?(How is returning an object by reference possible?)
矩阵如何存储在内存中?(How are matrices stored in memory?)
每个请求的Java新会话?(Java New Session For Each Request?)
css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
xcode语法颜色编码解释?(xcode syntax color coding explained?)
在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!