![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Event callback on thread I am trying to use psh as an object test bench for a client and service classes I have. Couple issues so far: 1) Using async socket reads at client. psh, however, calls Methods on a new thread and then exits. This causes socket read to error as the thread that started the async operation is not allowed to exit so error is thrown by socket. A hack workaround was to call the first beginreceive on a TP thread, not the calling thread. In a "normal" client, this is almost never an issue as you normally start with a main thread which never goes away (i.e. ui thread, console main thread). Surely someone has seen this before and has some advise. That does however beg the question of how this ever works if you post another read in the read callback which is an TP/IOCP thread that can get collected by the Pool. 2) My server object does not have issue #1 above, as it keeps its main thread as the accept loop. However, it does async reads also and calls a ReadReceive event for user code to handle, the callback is a TP thread as normal (or I think an IOCP thread). Anyway, I get this exception in psh: "System.Managment.Automation.PSInvalidOperationException: There is no Runspace available to run the scripts in this thread. You can provide one in the DefaultRunspace property..." Is there anyway I can use a psh script as an event handler in this case? TIA! -- William Stacey [C# MVP] |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Event callback on thread Should I restate the question? tia -- William Stacey [C# MVP] |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Event callback on thread Sorry for the delay. Unfortunately the answer is that there's no easy way to do what you want and no way to do it without writing some non-powershell code (at least that I've thought of). PowerShell runspaces are singlethreaded. If you try and execute a piece of code outside the runspace (i.e. not on the runspace thread), you'll get the exception you saw: "System.Managment.Automation.PSInvalidOperationException: There is no Runspace available to run the scripts in this thread. You can provide one in the DefaultRunspace property..." So you'll have to write some code to forward the events to a runspace in some manner. This type of event handling is one of the things we're actively investigating for V.Next. -bruce -- Bruce Payette [MSFT] Windows PowerShell Technical Lead Microsoft Corporation This posting is provided "AS IS" with no warranties, and confers no rights. "William Stacey [C# MVP]" <william.stacey@gmail.com> wrote in message news:upbQaloGHHA.3468@TK2MSFTNGP04.phx.gbl... > Should I restate the question? tia > > -- > William Stacey [C# MVP] > > |
My System Specs![]() |
| | #4 (permalink) |
| | Re: Event callback on thread Thanks Bruce. -- William Stacey [C# MVP] |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| How do the current thread get thread notification of OS intruption | .NET General | |||
| CTP3: Thread Safety of Wait-Event cmdlet | PowerShell | |||
| Start a new thread from an existing thread, which was started from atimer | .NET General | |||