Problem to export to excel

5 posts, 0 answers
  1. Oristhony
    Oristhony avatar
    2 posts
    Member since:
    Jul 2013

    Posted 04 Oct 2013 Link to this post

    I'm working with RadPivotGrid and RadPivotFieldList (WPF), the data comes from a cube olap. I'm trying to export to excel but when I do after a while the application crashes and I get the following exepcion:
    ContextSwitchDeadlock was detected
    Message: The CLR has been unable to transition from COM context 0x63ef2c8 to COM context 0x63ef438 for 60 seconds. The thread that owns the destination context/apartment is most likely either doing a non pumping wait or processing a very long running operation without pumping Windows messages. This situation generally has a negative performance impact and may even lead to the application becoming non responsive or memory usage accumulating continually over time. To avoid this problem, all single threaded apartment (STA) threads should use pumping wait primitives (such as CoWaitForMultipleHandles) and routinely pump messages during long running operations.

    as I can fix, I would give an example please?
  2. Rosen Vladimirov
    Rosen Vladimirov avatar
    640 posts

    Posted 07 Oct 2013 Link to this post

    Hi Oristhony,

    Most of the time this issue is caused by non-existing Directory which you are trying to open. The open file dialog is trying to open the last location which you've opened and if it doesn't exist or if it is a network location for which you don't have access currently, such exception is raised. You can check this discussion for possible workaround.

    Could you try it and inform us if it helps? I'm looking forward to hearing from you.

    Rosen Vladimirov
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. Oristhony
    Oristhony avatar
    2 posts
    Member since:
    Jul 2013

    Posted 07 Oct 2013 Link to this post

    Hi Rosen 

    First of all thank you very much for your cooperation. The cause of the problem was not because the directory does not exist trying to open, what happened was that intended to export very many records and the main thread is blocked.
    The solution was to assign another thread export to excel to the main interface to remain active

  4. Sunny
    Sunny avatar
    3 posts
    Member since:
    Nov 2016

    Posted 23 Feb in reply to Oristhony Link to this post

    Hi Oristhony,

    am facing the same problem contextswitchdeadlock. i even tried using another thread but its throwing exception another thread owns this object. even tried dispatcher solution it didn't work. Can u provide a sample over here.

    Thank you






  5. Polya
    Polya avatar
    242 posts

    Posted 27 Feb Link to this post

    Hi Sunny,

    The ContextSwitchDeadlock doesn't necessarily mean that the code has an issue, just that there is a potential. If you go to Debug > Exceptions in the menu and expand the Managed Debugging Assistants, you will find ContextSwitchDeadlock is enabled. If you disable this, Visual Studio will no longer warn you when items are taking a long time to process.

    The cases of a large export of many UI elements can be considered a long-running operation, thus probably the cause of the deadlock. However, that does not mean that operation will not pass after some time and that the export will fail.
    You can find more information about it here:

    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Back to Top