http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=171731&SiteID=1
| Цитата | When you are in debug mode, the CLR has some managed debug assistants (MDA's) that run around looking for bugs (or potential bugs in your code). The ContextSwitchDeadlock MDA behaves like this: a background thread runs that will (every 60 seconds) attempt to enter the STA that your code is running in. The way STA works is that a message based protocol is used to marshal calls. So in order for the MDA to enter, the marshalling message must get processed--which requires that a GetMessage or PeekMessage call be executed on the STA thread in that timeframe.
What this MDA message means then, is that your code has either explicitly or implicitly entered a codepath that is preventing control to flow back to Excel's main message loop. This could be caused by an infinite loop, or just a long operation. For example, you can trigger this MDA if you try to synchronously communicate with a database & end up blocking while you wait for a long query to complete.
In your case, since the CPU utilization is at 100% it sounds like you've gotten yourself into an infinite loop. My guess is that you aren't handling your Range.FindNext call correctly to terminate your loop. Here's what Help says about that method in remarks:
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
When the search reaches the end of the specified search range, it wraps around to the beginning of the range. To stop a search when this wraparound occurs, save the address of the first found cell, and then test each successive found-cell address against this saved address.
>>>>>>>>>>>>>>>>>>>>>>>>>>
Could it be that you aren't doing this and therefore that your loop termination condition is always false?
Hope that helps. If you still can't figure this out, feel free to post code as Martin suggested.
|
|