Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8151601
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T15:26:20+00:00 2026-06-06T15:26:20+00:00

I got a C# program which opens a EventWaitHandle like this to get triggered

  • 0

I got a C# program which opens a EventWaitHandle like this to get triggered by a Windows Service.

EventWaitHandle sampleEventHandle = new EventWaitHandle(false, EventResetMode.AutoReset, "Global\\sampleEvent");

When the program now gets killed (or dies due to a unexpected error), the EventWaitHandle is not being closed and when restarting the program the following error occurs:

System.UnauthorizedAccessException: Access to the path is denied.

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

at System.Threading.EventWaitHandle..ctor(Boolean initialState, EventResetMode mode, String name)

After a minute, the EventWaitHandle is getting closed and you can restart the Application.

Any ideas how to fix this issue?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T15:26:22+00:00Added an answer on June 6, 2026 at 3:26 pm

    This happens because the service has a handle opened on the same object. Which is to be expected, after all you are using this to implement signaling between the service and your program. The physical underlying Windows named object doesn’t get removed from global namespace until the last handle is closed.

    So getting an exception on this gives you a real problem diagnostic, the service is using the wrong handle and can never communicate with you when you restart your program. How this gets resolved after a minute is hard to guess, I have to assume that the service periodically calls OpenExisting().

    The solution is simple: it should be the service that creates the wait handle and your UI program should call OpenExisting(). The event now always exists, at least as long as the service is alive. And it if doesn’t then OpenExisting() gives you an excellent diagnostic of that with a WaitHandleCannotBeOpenedException

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So here I got this little program which everyone obviously understands. include <iostream> include
I got the program for Wifi tethering which i got a open (non secured)
Hello i'v got simple program which is couting characters in given text until line
I've got a program that takes 3 arrays (which are the same length, can
What I got: I got a textual representation which my program converts to a
I got this program that worked well 2 weeks ago, I didn't change any
I've got a program which uses app.config for storing some preferences. The problem is
I really have some troubles since 1 week ago. I got errors like this
i got a Delphi 7 program which has to copy a docx file. I'm
I've got a program in xna and I'm loading up 2gb+ of data (not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.