![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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) |
| | Re: Invoke Scriptblock with parameters in a new thread Quote: > I'm not a dev, but just wanted to point out that PowerShell v1 only > supports running under MTA. > > PowerShell v2 (currently at CTP3) supports STA (but still defaults as MTA). > > Marco > Hi Marco, I'm really pleased that you reflect on my problem!! I still tried to run the threads under MTA. But the result was, that the threads did not run parallel. I also tried the PowerShell V2 CTP. I found an example to create such a MTA but the used waithandle (from type ManualResetEvent) does not allow the threads to run parallel. I'm not very familiar with MTA. Perhaps you can help me ? Here is the try: protected override void BeginProcessing() { this.m_Runspace = Runspace.DefaultRunspace; } protected override void ProcessRecord() { //Create a Waithandle m_Waithandle = new ManualResetEvent(false); //Start a new thread in a multithreaded apartment Thread t = new Thread(new ThreadStart(DoWork)); t.SetApartmentState(ApartmentState.MTA); t.Start(); //Block the current thread m_Waithandle.WaitOne(); } public void DoWork() { //Set the runspace Runspace.DefaultRunspace = this.m_Runspace; //Invoke the Scriptblock this.m_myScriptBlock.Invoke(this.m_Array); if (m_Waithandle != null) { //Allow the thread to work m_Waithandle.Set(); } } Thank you |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Invoke Scriptblock with parameters in a new thread I just want to add that the only purpose is to start the command: this.m_myScriptBlock.Invoke(this.m_Array); in two or more parallel asynchronous threads. That means: Every time the Cmdlet is called, the command will be executed in a new thread. Thank you for your help. |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Start a new thread from an existing thread, which was started from atimer | .NET General | |||
| Powershell Invoke-Item and cmd line parameters | PowerShell | |||
| Invoke-Item and passing command line parameters | PowerShell | |||
| Functions and ScriptBlock parameters? | PowerShell | |||
| Scriptblock Parameters? | PowerShell | |||