Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

start System.Threading.Thread

342 views
Skip to first unread message

Selko

unread,
Aug 28, 2007, 2:16:00 PM8/28/07
to
Hy group!

I have created a gui form with some functions. When i start a function which
lasts longer the gui freezes and cant write out any text to the gui until the
function has finished

now i need System.Threading.Thread

but how can i start a thread from powershell
i have tried it so:

function test{
do something....
}
$start=new-object Threading.ThreadStart(test)
$thread=new-object System.Threading.Thread($start)

but this doesnt work

can you help me please?
thank you

Marco Shaw

unread,
Aug 28, 2007, 3:37:14 PM8/28/07
to

http://www.manning-sandbox.com/thread.jspa?messageID=61011

From what I understand, default PowerShell must run Windows forms in a
single thread, so what you're trying just won't work with v.1 anyways...

Marco

--
----------------
PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com

Selko

unread,
Aug 28, 2007, 3:56:03 PM8/28/07
to
hy

if i understand it.... there is no way to run threads from powershell??

Marco Shaw

unread,
Aug 28, 2007, 4:00:56 PM8/28/07
to
Selko wrote:
> hy
>
> if i understand it.... there is no way to run threads from powershell??

I don't *think* that's it... I think the issue is that you're trying to
use this within a Windows form.

I'm going to go quiet on this now because this is beyond what I know
today...

Hal Rottenberg

unread,
Aug 29, 2007, 9:40:08 AM8/29/07
to
Selko wrote:
> if i understand it.... there is no way to run threads from powershell??

There's some interesting blog posts and scripts out there about creating
job pools and background tasks. I don't know if any of them apply to
what you are trying to do however.

Hal Rottenberg
blog: http://halr9000.com
powershell category:
http://halr9000.com/article/category/programming/scripting/powershell/

Selko

unread,
Aug 30, 2007, 3:44:00 PM8/30/07
to
hy

can somebody help me?

how can i create Threads in a gui from powershell


thanks

Brandon Shell

unread,
Aug 30, 2007, 3:52:39 PM8/30/07
to

Oisin Grehan

unread,
Aug 30, 2007, 11:15:21 PM8/30/07
to

Hi there,

Suffice it to say, given the tools Powershell v1.0 provides you, this
cannot be done in any elegant or practical fashion. In technical
terms, Windows Forms instances demand a COM threading model of STA,
and demand thread affinity. Powershell employs the very opposite
model, it being multithreaded with an MTA apartment model.

Having said this, I'd keep an eye out for some cmdlets or tools that
will let you do this in the future, as it's not impossible,
technically speaking ;-)

- Oisin

Chip Webb

unread,
Feb 1, 2011, 9:26:39 PM2/1/11
to
After much futzing around I was finally able to start .NET threads in Powershell 2.0. This isn't a Winform script though, but I believe you could get that to work by makeing the new thread STA. Note that write-host (and friends) don't work because the PS host created with the Powershell() method doesn't have support.

# If it works you'll see notepad start
$s= ( notepad from_thread )
$ps_s=$s.GetPowerShell()
$smi=($ps_s.gettype().getmethods()| ? {
$_.name -eq "Invoke"})[0]
$fp = $smi.methodhandle.getfunctionpointer()
$ts=new threading.threadstart $ps_s,$fp
$thr = new threading.thread $ts
$thr.start()


>> On Tuesday, August 28, 2007 3:37 PM Marco Shaw wrote:

>> Selko wrote:
>>
>> http://www.manning-sandbox.com/thread.jspa?messageID=61011
>>
>> From what I understand, default PowerShell must run Windows forms in a
>> single thread, so what you're trying just won't work with v.1 anyways...
>>
>> Marco
>>

>> --
>> ----------------
>> PowerGadgets MVP
>> http://www.powergadgets.com/mvp
>>
>> Blog:
>> http://marcoshaw.blogspot.com


>>> On Tuesday, August 28, 2007 3:56 PM Selk wrote:

>>> hy


>>>
>>> if i understand it.... there is no way to run threads from powershell??
>>>
>>>

>>> "Marco Shaw" wrote:


>>>> On Tuesday, August 28, 2007 4:00 PM Marco Shaw wrote:

>>>> Selko wrote:
>>>>
>>>> I don't *think* that's it... I think the issue is that you're trying to
>>>> use this within a Windows form.
>>>>
>>>> I'm going to go quiet on this now because this is beyond what I know
>>>> today...
>>>>
>>>>
>>>> --
>>>> ----------------
>>>> PowerGadgets MVP
>>>> http://www.powergadgets.com/mvp
>>>>
>>>> Blog:
>>>> http://marcoshaw.blogspot.com


>>>>> On Wednesday, August 29, 2007 9:40 AM Hal Rottenberg wrote:

>>>>> Selko wrote:
>>>>>
>>>>> There's some interesting blog posts and scripts out there about creating
>>>>> job pools and background tasks. I don't know if any of them apply to
>>>>> what you are trying to do however.
>>>>>
>>>>> Hal Rottenberg
>>>>> blog: http://halr9000.com
>>>>> powershell category:
>>>>> http://halr9000.com/article/category/programming/scripting/powershell/


>>>>>> On Thursday, August 30, 2007 3:44 PM Selk wrote:

>>>>>> hy
>>>>>>
>>>>>> can somebody help me?
>>>>>>
>>>>>> how can i create Threads in a gui from powershell
>>>>>>
>>>>>>
>>>>>> thanks
>>>>>>
>>>>>>
>>>>>> "Hal Rottenberg" wrote:


>>>>>>> On Thursday, August 30, 2007 3:52 PM Brandon Shell wrote:

>>>>>>> AFAIK you cannot... you can use runspaces as illustrated here
>>>>>>> http://jtruher.spaces.live.com/Blog/cns!7143DA6E51A2628D!130.entry
>>>>>>>
>>>>>>> More info Here
>>>>>>> http://blogs.msdn.com/powershell/archive/2007/03/23/thread-apartmentstate-and-powershell-execution-thread.aspx
>>>>>>> http://blogs.msdn.com/powershell/rss_tag_ApartmentState.xml
>>>>>>>
>>>>>>> "Selko" <Se...@discussions.microsoft.com> wrote in message
>>>>>>> news:84F6F1CA-CB32-44DC...@microsoft.com...


>>>>>>>> Submitted via EggHeadCafe
>>>>>>>> SQL Server Table Valued Parameters / Types - Multiple Row Inserts
>>>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/1b4677b6-3be6-4b68-897f-e4829fa8f33b/sql-server-table-valued-parameters--types--multiple-row-inserts.aspx

0 new messages