Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. Error ContextSwitchDeadlock

Error ContextSwitchDeadlock

Scheduled Pinned Locked Moved Visual Basic
csharpperformancehelpmobile
25 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D desanti

    I can't offer smaller files. also I've read that I can do some configuration to ignore the message. but the problem is , what about when I finish my program and install it to client pc ? I've read also that I can use application.doevents. But executing this on every step of the loop cause the program to slow down. Is there way to call this only when necessary so windows can detect that my application is alive ?

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #8

    desanti wrote:

    also I've read that I can do some configuration to ignore the message. but the problem is , what about when I finish my program and install it to client pc ?

    You can; the IDE only breaks on exceptions that you want it to. What happens without the IDE can easily be tested by running your app outside of it. Then you'll know what happens on the client-PC.

    desanti wrote:

    I've read also that I can use application.doevents.

    No, you can't.

    desanti wrote:

    But executing this on every step of the loop cause the program to slow down.

    It is a loop inside a COM-component. Do you have the source to that control?

    desanti wrote:

    Is there way to call this only when necessary so windows can detect that my application is alive ?

    You application IS alive (and answering messages), but the COM-component that you're using is not. If you know WHY it is not answering messages, then it is not a problem. You simply wait for it to be done and hope it is not in an endless loop.

    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

    D 1 Reply Last reply
    0
    • L Lost User

      desanti wrote:

      also I've read that I can do some configuration to ignore the message. but the problem is , what about when I finish my program and install it to client pc ?

      You can; the IDE only breaks on exceptions that you want it to. What happens without the IDE can easily be tested by running your app outside of it. Then you'll know what happens on the client-PC.

      desanti wrote:

      I've read also that I can use application.doevents.

      No, you can't.

      desanti wrote:

      But executing this on every step of the loop cause the program to slow down.

      It is a loop inside a COM-component. Do you have the source to that control?

      desanti wrote:

      Is there way to call this only when necessary so windows can detect that my application is alive ?

      You application IS alive (and answering messages), but the COM-component that you're using is not. If you know WHY it is not answering messages, then it is not a problem. You simply wait for it to be done and hope it is not in an endless loop.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

      D Offline
      D Offline
      desanti
      wrote on last edited by
      #9

      there are people that have resolved this with application.doevents : ContextSwitchDeadlock Errormessage[^]

      L D 2 Replies Last reply
      0
      • D desanti

        there are people that have resolved this with application.doevents : ContextSwitchDeadlock Errormessage[^]

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #10

        If the loop is in your program, then it should be in a backgroundworker on its own thread. If the loop is inside the COM-component, you can't change much. Application.DoEvents is a crutch for people doing too much on the UI-thread. --edit Go to the menu "Debug / Exceptions", find "Managed Debugging Assistants", uncheck ContextSwitchDeadlock. And sometimes, the message is even bogus[^].

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

        D 1 Reply Last reply
        0
        • L Lost User

          If the loop is in your program, then it should be in a backgroundworker on its own thread. If the loop is inside the COM-component, you can't change much. Application.DoEvents is a crutch for people doing too much on the UI-thread. --edit Go to the menu "Debug / Exceptions", find "Managed Debugging Assistants", uncheck ContextSwitchDeadlock. And sometimes, the message is even bogus[^].

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

          D Offline
          D Offline
          desanti
          wrote on last edited by
          #11

          the loop is inside my program , but the problem is that inside the loop I use the values from some controls in my form ( there's a spreadsheet control that have all the data from excel file or directly written by user and some other textboxes that have all the data and parameters that I use on that loop). so I can't use a background worker because I've read that I can't use the UI controls inside it. Or I'm wrong !!!!!

          L 1 Reply Last reply
          0
          • D desanti

            the loop is inside my program , but the problem is that inside the loop I use the values from some controls in my form ( there's a spreadsheet control that have all the data from excel file or directly written by user and some other textboxes that have all the data and parameters that I use on that loop). so I can't use a background worker because I've read that I can't use the UI controls inside it. Or I'm wrong !!!!!

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #12

            desanti wrote:

            so I can't use a background worker because I've read that I can't use the UI controls inside it. Or I'm wrong !!!!!

            You can't access them directly, you'd have to do an invoke. Is this actually occuring in the release-version?

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

            D 1 Reply Last reply
            0
            • L Lost User

              desanti wrote:

              so I can't use a background worker because I've read that I can't use the UI controls inside it. Or I'm wrong !!!!!

              You can't access them directly, you'd have to do an invoke. Is this actually occuring in the release-version?

              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

              D Offline
              D Offline
              desanti
              wrote on last edited by
              #13

              Yes , I noticed at least 2-3 times in the release version. I've tried with Application.doevents executed on every step of the loop , and no problems but the application slows down. So i'm asking if there's a way to know the interval that windows check for application status , so i'm calling application.doevents not on every step of the loop but for example every x seconds ? Is this possible ?

              L 1 Reply Last reply
              0
              • D desanti

                Yes , I noticed at least 2-3 times in the release version. I've tried with Application.doevents executed on every step of the loop , and no problems but the application slows down. So i'm asking if there's a way to know the interval that windows check for application status , so i'm calling application.doevents not on every step of the loop but for example every x seconds ? Is this possible ?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #14

                desanti wrote:

                So i'm asking if there's a way to know the interval that windows check for application status , so i'm calling application.doevents not on every step of the loop but for example every x seconds ? Is this possible ?

                I never found any specification on how often Windows checks it, might even vary between versions. Instead of doing it every N seconds, you could do it after N items. Still, that metric may vary on another system.

                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                D 1 Reply Last reply
                0
                • L Lost User

                  desanti wrote:

                  So i'm asking if there's a way to know the interval that windows check for application status , so i'm calling application.doevents not on every step of the loop but for example every x seconds ? Is this possible ?

                  I never found any specification on how often Windows checks it, might even vary between versions. Instead of doing it every N seconds, you could do it after N items. Still, that metric may vary on another system.

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                  D Offline
                  D Offline
                  desanti
                  wrote on last edited by
                  #15

                  But if you see my original error message , it says.... "60 seconds". Maybe this is the time or is another thing ?

                  L 1 Reply Last reply
                  0
                  • D desanti

                    But if you see my original error message , it says.... "60 seconds". Maybe this is the time or is another thing ?

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #16

                    :-D Yup, that's what it says, you're right. Get the current time before the loop. Inside the loop, distract that value from the current time. If the difference is more than N seconds, call your doevents.

                    Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                    D 1 Reply Last reply
                    0
                    • L Lost User

                      :-D Yup, that's what it says, you're right. Get the current time before the loop. Inside the loop, distract that value from the current time. If the difference is more than N seconds, call your doevents.

                      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                      D Offline
                      D Offline
                      desanti
                      wrote on last edited by
                      #17

                      a Timer object will be a help or no ?

                      L 1 Reply Last reply
                      0
                      • D desanti

                        a Timer object will be a help or no ?

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #18

                        Which timer-object? There's multiple, and one of them relies on the application processing messages (ie, not being too busy). It's easier to simply check inside the loop how much time has passed.

                        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                        D 1 Reply Last reply
                        0
                        • L Lost User

                          Which timer-object? There's multiple, and one of them relies on the application processing messages (ie, not being too busy). It's easier to simply check inside the loop how much time has passed.

                          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                          D Offline
                          D Offline
                          desanti
                          wrote on last edited by
                          #19

                          Sorry , Timer Control

                          L 1 Reply Last reply
                          0
                          • D desanti

                            Sorry , Timer Control

                            L Offline
                            L Offline
                            Lost User
                            wrote on last edited by
                            #20

                            The one from System.Windows.Forms says this in the docs;

                            Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in Windows Forms applications and must be used in a window.

                            Meaning it won't fire if it doesn't get to process the message.

                            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                            D 1 Reply Last reply
                            0
                            • L Lost User

                              The one from System.Windows.Forms says this in the docs;

                              Implements a timer that raises an event at user-defined intervals. This timer is optimized for use in Windows Forms applications and must be used in a window.

                              Meaning it won't fire if it doesn't get to process the message.

                              Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                              D Offline
                              D Offline
                              desanti
                              wrote on last edited by
                              #21

                              So , the only solution remain to manually calculate the time inside the loop.

                              L 1 Reply Last reply
                              0
                              • D desanti

                                So , the only solution remain to manually calculate the time inside the loop.

                                L Offline
                                L Offline
                                Lost User
                                wrote on last edited by
                                #22

                                ..which is not that hard; there's an example a few posts below.

                                Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^] "If you just follow the bacon Eddy, wherever it leads you, then you won't have to think about politics." -- Some Bell.

                                1 Reply Last reply
                                0
                                • D desanti

                                  And what you propose as a solution , because I've read that I should use a background worker , but the problem is that I need to access the UI objects during the process and this is not possible on a background worker.

                                  D Offline
                                  D Offline
                                  Dave Kreskowiak
                                  wrote on last edited by
                                  #23

                                  Solution? Ignore it. The message only shows up when debugging the app. And you're wrong about the BackgroundWorker not having access to the controls. Technically, you don't have access to them, but you can get at the controls if you supply method to update the controls and Invoke calls to them. Using the BackgroundWorker, or some other threading/Task model, will free up the UI thread to pump messages. This will also make the warning message you're seeing disappear. Also, if you're doing everything in this long-running operation on the UI (startup) thread, then your controls are not getting repainted anyway. If the UI thread is busy with your operation, it can't respond to all the WM_PAINT messages that are piling up in the message pump. So, during this operation, what could you possibly be updating in the controls since nobody can see those changes? If you're going to do a long-running operation with control interactions, you have to do it correctly, otherwise you run into little issues like what you're seeing.

                                  Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                                  Dave Kreskowiak

                                  1 Reply Last reply
                                  0
                                  • D desanti

                                    I can't offer smaller files. also I've read that I can do some configuration to ignore the message. but the problem is , what about when I finish my program and install it to client pc ? I've read also that I can use application.doevents. But executing this on every step of the loop cause the program to slow down. Is there way to call this only when necessary so windows can detect that my application is alive ?

                                    D Offline
                                    D Offline
                                    Dave Kreskowiak
                                    wrote on last edited by
                                    #24

                                    If you think you have to use Application.DoEvents, this is a sign you're doing something very wrong.

                                    Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                                    Dave Kreskowiak

                                    1 Reply Last reply
                                    0
                                    • D desanti

                                      there are people that have resolved this with application.doevents : ContextSwitchDeadlock Errormessage[^]

                                      D Offline
                                      D Offline
                                      Dave Kreskowiak
                                      wrote on last edited by
                                      #25

                                      No, they haven't "solved" it. What they've done is gotten around the warning message without actually fixing the problem.

                                      Asking questions is a skill CodeProject Forum Guidelines Google: C# How to debug code Seriously, go read these articles.
                                      Dave Kreskowiak

                                      1 Reply Last reply
                                      0
                                      Reply
                                      • Reply as topic
                                      Log in to reply
                                      • Oldest to Newest
                                      • Newest to Oldest
                                      • Most Votes


                                      • Login

                                      • Don't have an account? Register

                                      • Login or register to search.
                                      • First post
                                        Last post
                                      0
                                      • Categories
                                      • Recent
                                      • Tags
                                      • Popular
                                      • World
                                      • Users
                                      • Groups