{"id":1935,"date":"2009-11-18T15:33:54","date_gmt":"2009-11-18T23:33:54","guid":{"rendered":"http:\/\/www.sapien.com\/blog\/2009\/11\/18\/primalforms-2009-new-packager-sta-mode\/"},"modified":"2009-11-18T15:33:54","modified_gmt":"2009-11-18T23:33:54","slug":"primalforms-2009-new-packager-sta-mode","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2009\/11\/18\/primalforms-2009-new-packager-sta-mode\/","title":{"rendered":"PrimalForms 2009: New Packager STA Mode"},"content":{"rendered":"<p>Last month\u2019s service build included a new addition to PrimalForms 2009\u2019s packager: STA Mode (Single Thread Apartment), which allows you to perform operations that may have previously failed, such as accessing Window\u2019s Clipboard.<\/p>\n<p>Some of you may have attempted to use the Clipboard in your forms only to encounter issues within PowerShell.<\/p>\n<p>For example, if you try to copy data from a DataGrid you will get the following error:<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2009\/11\/CopyFromGrid.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Copy From Grid\" style=\"border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px\" height=\"102\" alt=\"Copy From Grid\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2009\/11\/CopyFromGrid_thumb.png\" width=\"244\" border=\"0\" \/><\/a> <\/p>\n<p>This issue also comes up if you try to access the Clipboard directly from within Powershell:<\/p>\n<p>[System.Windows.Forms.Clipboard]::SetText(&quot;Paste this text to the clipboard&quot;)<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2009\/11\/ClipboardError.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Clipboard Error\" style=\"border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px\" height=\"67\" alt=\"Clipboard Error\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2009\/11\/ClipboardError_thumb.png\" width=\"244\" border=\"0\" \/><\/a> <\/p>\n<p>These issues arise because PowerShell runs in a MTA mode (Multi-Thread Apartment), yet the clipboard operations require the process to be in STA mode (Single Thread Apartment). A full explanation of Thread Apartments goes beyond the purpose of this blog, so we will provide a very condensed explanation: Thread Apartments boil down to how a process manages legacy COM objects and their communications between multiple threads. <\/p>\n<p>The new PrimalForms 2009 Packager\u2019s STA Mode allows you to package scripts that can access STA dependent operations, such as the Clipboard. To create STA packages, you simply check the \u201cRun In STA Mode\u201d options in the General Packager Settings page and press the Build button.<\/p>\n<p><a href=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2009\/11\/PackagerSettings.png\"><img loading=\"lazy\" decoding=\"async\" title=\"Packager Settings\" style=\"border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px\" height=\"159\" alt=\"Packager Settings\" src=\"http:\/\/www.sapien.com\/blog\/wp-content\/uploads\/2009\/11\/PackagerSettings_thumb.png\" width=\"244\" border=\"0\" \/><\/a> <\/p>\n<p>Now your packaged scripts can access the clipboard without encountering the issues mentioned above. <\/p>\n<p>Please note that STA Mode is only compatible with WIN32 Windows and WIN64 Windows packager settings. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last month\u2019s service build included a new addition to PrimalForms 2009\u2019s packager: STA Mode (Single Thread Apartment), which allows you to perform operations that may have previously failed, such as accessing Window\u2019s Clipboard. Some of you may have attempted to use the Clipboard in your forms only to encounter issues within PowerShell. For example, if [&hellip;]<\/p>\n","protected":false},"author":10,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[509,21,25],"tags":[537,313,28,314,538],"class_list":["post-1935","post","type-post","status-publish","format-standard","hentry","category-primalforms-software-news","category-software-news","category-windows-powershell","tag-clipboard","tag-forms","tag-powershell","tag-primalforms","tag-sta"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1935","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=1935"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/1935\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=1935"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=1935"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=1935"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}