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 7709685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:55:26+00:00 2026-06-01T00:55:26+00:00

Assume that: An ASP.NET MVC3 Page (using visual studio debug server) calls a WCF

  • 0

Assume that:

  • An ASP.NET MVC3 Page (using visual studio debug server) calls a WCF Service (self hosted, net.tcp binding).
  • Service uses ThreadPool to do some work, but returns immediately a value to the client
  • Client gets the value and redirects to another page.
  • A few seconds later the Server crashes with an “ObjectDisposedException / Safe handle has been released)

First I thought that the proxy would be disposed after the page redirect and the wcf service would get disposed too, but even when I’m not using the ThreadPool (by calling the method within the wcf service thread) I get the exception too. I don’t get it.

I’m not really into web programming. What am I doing wrong?

Client
Global.asax (registering channel factory)

protected void Application_Start()
{
  builder.Register(c => new ChannelFactory<IWcfBakeryService >("")).SingleInstance();

  builder.Register(c => c.Resolve<ChannelFactory<IWcfBakeryService>>()
        .CreateChannel())
        .UseWcfSafeRelease();
}

Repository (channel injected by Autofac)

public BakeryRepository(IWcfBakeryService orderService)
{

}


public ReciepeResponse RequestReciepe(CakeDto webOrder)
{
    [...] 
    return service.RequestReciepe(request);
}

Server:
Contract

[ProtoBehavior, OperationContract(IsTerminating=false)]
ReciepeResponse RequestReciepe(ReciepeRequest request);

Service-Implementation

[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]

RequestReciepe / Service Method

ThreadPool.QueueUserWorkItem(new WaitCallback(DoWork));
return new ReciepeResponse() { SomeValue = "Some Value"};

Exception Stacktrace (catched by AppDomain UnhandledException)

bei System.Runtime.InteropServices.SafeHandle.DangerousAddRef(Boolean& success)
bei System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, Boolean& success)
bei Microsoft.Win32.Win32Native.SetEvent(SafeWaitHandle handle)
bei System.Threading.EventWaitHandle.Set()
bei System.Runtime.Remoting.Messaging.AsyncResult.SyncProcessMessage(IMessage msg)
bei System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)
bei System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.DoAsyncCall()
bei System.Runtime.Remoting.Proxies.AgileAsyncWorkerItem.ThreadPoolCallBack(Object o)
bei System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
bei System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
bei System.Threading.ThreadPoolWorkQueue.Dispatch()
bei System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
  • 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-01T00:55:27+00:00Added an answer on June 1, 2026 at 12:55 am

    Solved.

    My Wcf Service uses existing business logic. Another developer used an implementation of an custom Parallel class for multithreading purposes, which was calling:

    iAsyncResult.AsyncWaitHandle.Close(); 
    

    The Method who used the Parallel class wasn’t designed thread-safe. After doing this, everything seems to work fine.

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

Sidebar

Related Questions

I have an app that calls my ASP.NET page on my server, every 30
Assume we have an ASP.NET MVC3 Web site that makes use of Entity Framework
Assume that my ASP.NET application is making 4 separate database calls. If after the
I have been using the embedded server that visual studio has to test my
I am using Asp.net MVC3 and C# and IIS 7.5. I want that once
I am writing a web application on Asp.Net MVC 3. Assume that we have
First hi and thanks in advance in ASP.NET : assume that i have a
Assume I have an ASP.NET MVC app that's not doing anything too fancy (no
I am uploading large files to an ASP.NET server using a standard HTML <input>
If I have an MVC3 ASP.net page which contains a the model iEnumerable<mymodel.CarsForHire> -

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.