Page 1 of 1

Unable to register event

Posted: Mon May 14, 2012 8:56 pm
by pringtef
OS : Win7 x64 (SP1)
PrimalStudio Version : 3.0.3.0
Powershell v2

I'm struggling to find a way within the PrimalStudio 2012 interface to properly register an event in a project so that i can process its eventargs.
Code for registration is below

$webclient = New-Object System.Net.WebClient
Register-ObjectEvent $webclient DownloadProgressChanged -SourceIdentifier WebClient.DownloadProgressChanged

I've tried the above in Globals.ps1, Startup.pfs, and MainForm.pff without success, whenever i try a :-
get-event -SourceIdentifier WebClient.DownloadProgressChanged

I get ERROR: Get-Event : Event with source identifier 'WebClient.DownloadProgressChanged' does not exist.


So far the only way i've found out to get round this to manually edit the ps1 file that is generated by PrimalStudio 2012 (via Export), and enter the registration code code in the #region Import Assemblies section of the file. If i do that, i can then access the event from anywhere in my script. This is a bit inconvenient though.

Is there a way for me to do this within PrimalStudio?

thanks,

tim
pringtef2012-05-15 03:58:18

Unable to register event

Posted: Tue May 15, 2012 4:00 am
by davidc
Register-ObjectEvent may not trigger while running a Form. Please try the following instead: $webclient.add_DownloadProgressChanged($scriptBlock)David

Unable to register event

Posted: Fri May 18, 2012 3:10 am
by pringtef
Thanks David, will try this.

Unable to register event

Posted: Fri May 18, 2012 9:15 pm
by pringtef
Works great, and allows me to access all the form objects as well. thanks.