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
  1. Home
  2. General Programming
  3. C#
  4. Could you please check this exception?

Could you please check this exception?

Scheduled Pinned Locked Moved C#
designquestion
3 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.
  • S Offline
    S Offline
    SungBae Han
    wrote on last edited by
    #1

    hello... when i wase test my solution, i found exception. message is... ---------------- The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone). ---------------- that is riaseup after this code

    p_han = OpenProcess(1, false, (IntPtr)ps.Id);
    TerminateProcess(p_han, 0);
    CloseHandle(p_han);

    this code is kill process from my ui form command. why raiseup is exception ?

    D L 2 Replies Last reply
    0
    • S SungBae Han

      hello... when i wase test my solution, i found exception. message is... ---------------- The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone). ---------------- that is riaseup after this code

      p_han = OpenProcess(1, false, (IntPtr)ps.Id);
      TerminateProcess(p_han, 0);
      CloseHandle(p_han);

      this code is kill process from my ui form command. why raiseup is exception ?

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

      There's not enough information to troubleshoot this. The message your exception is supplying has, on the surface, nothing to do with the code you posted. One problem I see is that your opening a process, then killing it while you have the process open. Try closing the process first, THEN killing it. It's entirely possible that the handle you get in the OpenProcess line is no longer valid when you try and Close it. Frankly, this reeks of copy'n'paste coding.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak

      1 Reply Last reply
      0
      • S SungBae Han

        hello... when i wase test my solution, i found exception. message is... ---------------- The Undo operation encountered a context that is different from what was applied in the corresponding Set operation. The possible cause is that a context was Set on the thread and not reverted(undone). ---------------- that is riaseup after this code

        p_han = OpenProcess(1, false, (IntPtr)ps.Id);
        TerminateProcess(p_han, 0);
        CloseHandle(p_han);

        this code is kill process from my ui form command. why raiseup is exception ?

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

        This error could occur due to cross-thread operations. You may want to check InvokeRequired and call your methods using either Invoke or BeginInvoke.

        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