Waitall for multiple handles on a sta thread is not supported. (original)
Source: Internet
Author: User
When developing winform, you have encountered the need to set main to MTA thread mode, but sometimes some ProgramIt is not supported, such as the clipboard. Therefore, use the following methods to solve thread t = new thread (New threadstart (method ));
T. setapartmentstate (apartmentstate. Sta );
T. Start (); that is, the solution is achieved by setting it to apartmentstate. Sta. Later, when allodrop in winform is set to true, the following error occurs: waitall for multiple handles on a sta thread is not supported. It seems that you still have to identify main as stathread. Therefore, we had to seek a reverse solution. After some painstaking efforts, we were relieved to use the following methods to solve the problem.
Private void waitall (waithandle [] waithandles ){
If (thread. currentthread. apartmentstate = apartmentstate. Sta ){
// Use foreach to wait for each handle in multiple threads
Foreach (waithandle mywaithandle in waithandles ){
Waithandle. waitany (New waithandle [] {mywaithandle });
}
}
Else {
Waithandle. waitall (waithandles );
}
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service