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
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
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...
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/
can somebody help me?
how can i create Threads in a gui from powershell
thanks
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...
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
# 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