Blocking on Process.Start() with .Net 4.5 RRS feed

  • Question

  • I have a multithread console application. The main thread starts other and then waiting for key press from user 


    One of other threads then trying to start another console application and redirect it's input/output and get blocked on 


    This problem appears only on machines where .net framework 4.5 installed.

    I found that the key of this problemm is deadlock in mscorlib.dll. When I tries to redirect input/output the following code executes in Process.Start(startinfo)

    standardInput = new StreamWriter(new FileStream(standardInputWritePipeHandle, FileAccess.Write, 4096, false), Console.InputEncoding, 4096); 

    this calls Console.InputEncoding wich locks Console like this


    At the other side, I've already called Console.ReadKey() from main thread, witch locks the same object in .Net 4.5 but not in .Net 4.0.

    Are there any solution to avoid ReadKey() blocking Console instead of using 


    wich generate 2 context switch for every call of Console.KeyAvailible?

    Thursday, October 4, 2012 11:41 AM

All replies

  • Wow, thank you, nice find.

    I just spent the last day trying to figure out why I was seeing this issue and I was the only one. Turns out I'm the only one here with 2012/.net 4.5 installed. 

    What the ___ were Microsoft thinking making 4.5 an in-line update to 4.0, how many applications out there in the wild will be broken by these issues. 

    Friday, October 5, 2012 4:58 AM
  • Hi Niellune,

    Welcome to the MSDN Forum.

    How about read

    Best regards,

    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, October 5, 2012 7:04 AM
  • Dear Mike,

    Console.Read is not a suitable alternative for us, because our console app is waiting for enter key to shut down, and it's also waiting for other keys to display its status and perform some other actions.

    We could use Console.ReadLine instead, but pressing enter after each special key is something we'd prefer to avoid.

    So, are there any other simple alternatives to the spin waiting for KeyAvailable, Niellune was mentioning above?


    Friday, October 5, 2012 10:06 AM
  • Hi, Mike.

    I just tested your solution and found that Read and ReadLine do there work well and does't block console obkject.

    But this method applies some restrictions if i want to process keys that user pressed

    - It waits for Enter to be pressed

    - It can't handle key modifiers

    - It can't handle special keys

    I'm sory that don't describe my task well, but originaly it looks like

    while (ProcessUserKey(Console.ReadKey())) { }

    where bool ProcessUserKey(ConsoleKeyInfo key) perfoms some action for different keys and returns true if eneter was perssed (exit app)

    • Edited by Niellune Friday, October 5, 2012 10:31 AM
    Friday, October 5, 2012 10:08 AM
  • Sorry to hear that you are running into an issue. We are looking into this. Please contact us on netfx45compat at Microsoft dot com.



    (.NET Framework Compatibility Team)

    Varun Gupta - MSFT

    Sunday, October 7, 2012 6:19 PM
  • Hi Extra330 and Niellune,

    .NET team is trying to reproduce this issue to investigate. Could you send us repro code on netfx45compat at Microsoft dot com?



    (.NET Framework Compatibility team)

    Varun Gupta - MSFT

    Monday, October 8, 2012 12:13 AM
  • Hi Varun.

    I've sent test application that describes this issue on adress that you provide.

    Can I help you more?

    Tuesday, October 9, 2012 3:23 PM
  • Hi Niellune,

    I have not got your test app, can you email me once again on netfx45compat at Microsoft dot com?

    Thank you,


    Varun Gupta - MSFT

    Thursday, January 17, 2013 10:10 PM