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.
  • 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