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

  • Home
  • SEARCH
  • 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 1085383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:40:56+00:00 2026-05-16T22:40:56+00:00

I am trying to integrate some new code I wrote for programmatically interacting with

  • 0

I am trying to integrate some new code I wrote for programmatically interacting with Exchange 2010 via Remote Powershell into an existing WinForms application. My code works in an isolated test application, but when I run the code in the context of my app the call to Runspace.Open() blocks for a very long time — well past the OpenTimeout value of 60 seconds which I am specifying in the WSManConnectionInfo instance. To me, this suggests that there is something in our application code which is creating the issue but I’m having trouble narrowing down what those potential causes could be. The application is multithreaded and uses both BackgroundThreadWorker and the ThreadPool; in fact, my code runs via the ThreadPool in the application. But I’ve already tried simulating this in my test harness and the code works fine when called as a callback from the ThreadPool too.

Here’s the code (with error handling removed and constant definitions put nearby):

const string EXCHANGE_PS_URI_FORMAT = "http://{0}/PowerShell/";
string uriString = string.Format(EXCHANGE_PS_URI_FORMAT, HostName);
Uri connectionUri = new Uri(uriString);

PSCredential creds = new PSCredential(username, securePwd);

const string EXCHANGE_PS_SCHEMA_URL = 
    "http://schemas.microsoft.com/powershell/Microsoft.Exchange";
WSManConnectionInfo connectionInfo = 
    new WSManConnectionInfo(connectionUri, EXCHANGE_PS_SCHEMA_URL, creds);

const int DEFAULT_OPEN_TIMEOUT = 1 * 60 * 1000; // 1 minute
connectionInfo.OpenTimeout = DEFAULT_OPEN_TIMEOUT;
const int DEFAULT_OPERATION_TIMEOUT = 4 * 60 * 1000; // 4 minutes
connectionInfo.OperationTimeout = DEFAULT_OPERATION_TIMEOUT;

using (Runspace rs = RunspaceFactory.CreateRunspace(connectionInfo))
{
    // BUGBUG: WHY IS THIS FAILING TO RETURN?
    rs.Open(); // <-- HANGS HERE

    ICollection<PSObject> newReqResults = null;
    PipelineReader<object> newReqErrors = null;
    try
    {
        using (Pipeline pipeline = rs.CreatePipeline())
        {
            // cmd instance is already instantiated with cmdlet info, params, etc.
            pipeline.Commands.Add(cmd);

            //Invoke the command and return the results and errors
            newReqResults = pipeline.Invoke();
            newReqErrors = pipeline.Error;
        }
    }

    // Code to parse results and/or errors...

The call stack when the code hangs on the Runspace.Open() seems to show that the internal .NET code is stuck on a wait call, but I’m at a loss on how to proceed. As I said earlier, this code works fine in my test app even if called as a ThreadPool callback, so I’m wondering what could be in our main app code that could be causing this (synchronization context or the thread identity or something else?) Any help would be greatly appreciated. Please let me know if I’ve neglected to include some relevant info and I’m happy to include it. Thanks!

[In a sleep, wait, or join] 
mscorlib.dll!System.Threading.WaitHandle.WaitOne(long timeout, bool exitContext) + 0x2f bytes   
mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext) + 0x25 bytes    
mscorlib.dll!System.Threading.WaitHandle.WaitOne() + 0xd bytes  
System.Management.Automation.dll!System.Management.Automation.Runspaces.AsyncResult.EndInvoke() + 0x14 bytes    
System.Management.Automation.dll!System.Management.Automation.Runspaces.Internal.RunspacePoolInternal.EndOpen(System.IAsyncResult asyncResult) + 0xb2 bytes 
System.Management.Automation.dll!System.Management.Automation.Runspaces.Internal.RemoteRunspacePoolInternal.Open() + 0x1a bytes 
System.Management.Automation.dll!System.Management.Automation.Runspaces.RunspacePool.Open() + 0x48 bytes    
System.Management.Automation.dll!System.Management.Automation.RemoteRunspace.Open() + 0x73 bytes    
  • 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-05-16T22:40:57+00:00Added an answer on May 16, 2026 at 10:40 pm

    Is it possible that when you run the program in the threadpool, that the thread is blocked? Perhaps what you really want here is to call OpenAsync rather than Open.

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

Sidebar

Related Questions

We've got some problems with an external company trying in integrate into a WCF
I'm trying to integrate a public message board service into an existing web site.
I'm trying to integrate some photo related functionality with my site and facebook. I
While trying to integrate Yahoo Media Player into my own website, I want to
I am trying to integrate the function into a map where you can enter
I'm using JSF/Facelets, and I'm trying to iterate over some Document objects (custom object)
I'm trying to integrate running Fitnesse tests from MSBuild im my nightly build on
We are trying to integrate tests in our daily builds using TestComplete, so far
I'm trying to integrate a NSURLConnection object with UIProgressView, so I can update the
I'm trying to integrate our Source Control(SourceAnywhere) with VS and are getting a lot

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.