Trap and Windows Forms

Hi, usually i have a  trap{} in my scripts to handle and log(!) all
unforseen exceptions which i have
not otherwise handled via Try/catch.
This works great.
But, when i have a script with windows forms, all exceptions will be displayed automatically as a system-popup
and the code inside trap{} is not executed, so the error never gets logged.
Why is the trap being ignored?
And how do i make my form execute the trap in case of an exception?
Thanks, Rob 
http://www.administrator.de/

Thanks for your reply David.
Separate runspace? Mhm, I dont think so. Otherwise I would not be able to access variables of the root script (that set up the form), would I? 
Also i do not set up confined script blocks to the events. They call functions in the script which call other functions and so on. Its
all one script, only that actions are triggered by events.
That depends on how the runspace is set up (and in this case, it's all being done by the PowerShell engine, so I'm not sure exactly what's happening.)  It's possible to give different runspaces access to the same variables, functions, etc (though you
have to be careful when doing that, as you may create race conditions.)
As I said, I don't know if that's actually what's happening here, but it would make sense.  Your main thread is blocking on $form1.ShowDialog(); until that function returns, execution would never jump to your trap block.
Anyhow, regardless of the technical details of why it's behaving this way, making sure you set up a new trap statement within those events (or the functions they call) does seem to work:
trap { Invoke-ErrorHandler -ErrorRecord $_ }
function Invoke-ErrorHandler
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[System.Management.Automation.ErrorRecord]
$ErrorRecord
Write-Host "This statement called from the error handler."
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[System.Windows.Forms.Application]::EnableVisualStyles()
$form1 = New-Object 'System.Windows.Forms.Form'
$form1.ClientSize = '200, 150'
$button1 = New-Object 'System.Windows.Forms.Button'
$button1.Location = '54, 45'
$button1.Size = '75, 23'
$form1.Controls.Add($button1)
$button1.add_mouseclick({ TestFunction })
function TestFunction {
trap { Invoke-ErrorHandler -ErrorRecord $_ }
$button1.FalseProperty = 1
# TestFunction ## If you call the function here, instead of the command below, the trap catches the error
$form1.ShowDialog()

Similar Messages

  • Need help with an Aforge and windows forms memory stack-up issue

    Hello,
    I am experiencing a strange memory stack-up in my c# windows form program that occurs all the time on slow PCs, and when the windows form loses focus or is otherwise interrupted on faster PCs.
    The program I have written uses Aforge to get images from my webcam, which I then display in an Aforge picturebox control (CurrImagePic in code) in the windows form.  The images are switched into the picture box and then disposed at the camera's native
    framerate, so it appears as video to the user, not still images.  The picture box is 1080x1920, but the space for it in the form is smaller and so I allow the user to scroll around the picture.
    After about ~30 seconds of memory-stable operation on slower PCs, the problem begins.  On faster PCs, the problem only occurs when holding down scroll bar arrows or clicking and dragging around either scroll bar, and if I lock the PC or bring up the
    Ctrl+Alt+Delete menu.
    The problem itself is that memory used by the program starts to increase in very large chunks, leading to an out of memory crash.  This is unstoppable on slower PCs, but on the faster PCs if you stop scrolling or return from the lock/Ctrl+alt+delete
    menu, the program stabilizes at the higher memory usage level.  The memory that was accrued during scrolling or while in the lock menu is never collected by the garbage collector.  I've even tried to put in a button that forces a GC.collect() when
    pressed, and it does not reduce this memory usage.
    I've run perfmon and found that the memory increase is on the unmanaged heap, but I don't know if it's coming from bitmaps which are not being disposed or what it could be from.  It's been impossible to track down since it does not occur except in the
    above conditions.  I've tried various solutions (like moving my image processing out of the event handler and even using both global flags and a "lock" statement to try and ensure that only one thread or frame can access the image processing
    and displaying method at at time, but I have seen no change.  In fact, I am now seeing some unexplained small jumps in memory usage that I wasn't seeing before I put in the lock and moved the processing out of the handler.
    Has anyone run into situations like this?  I am at a loss for what I need to fix.  I think the problem is based around my Aforge event handler and image processing method if it is in my code at all - but I also have a suspicion that this is something
    deeper in the windows form code that I am either misusing or that can't keep up with the demands of my code.  Code below:
    //Applicable Globals to this code snippet
    private bool ALLOWFRAME = true;
    private Object FRAMEKEY = new Object();
    private VideoCaptureDevice COMPVID;
    private Bitmap TMPLTCAP;
    private System.Drawing.Image OLDIMAGE;
    private bool RCRDPIC = false;
    private void COMPVID_NewFrame(object sender, NewFrameEventArgs eventArgs)
    //Only process a frame when another is done processing
    if (ALLOWFRAME == true)
    ALLOWFRAME = false;
    Bitmap PassFrame = AForge.Imaging.Image.Clone(eventArgs.Frame);
    ProcessFrame(PassFrame);
    PassFrame.Dispose();
    private void ProcessFrame(Bitmap frameIn)
    lock (FRAMEKEY)
    if (OLDIMAGE != null) { OLDIMAGE.Dispose(); }
    //Call comparison method if flag is set.
    if (COMPON == true)
    Difference TmpltFilter = new Difference(TMPLTCAP);
    TmpltFilter.ApplyInPlace(frameIn);
    OLDIMAGE = CurrImagePic.Image;
    CurrImagePic.Image = AForge.Imaging.Image.Clone(frameIn);
    OLDIMAGE.Dispose();
    else
    OLDIMAGE = CurrImagePic.Image;
    CurrImagePic.Image = AForge.Imaging.Image.Clone(frameIn);
    OLDIMAGE.Dispose();
    //Toggle the flag back to false to show it's safe (i.e., comparisons have stopped)
    //for the result-recording method to copy from the picture box if it is attempting to copy
    if (RCRDPIC == true)
    RCRDPIC = false;
    ALLOWFRAME = true;

    As you are using third party tools and controls, and I cannot find posts on parallel cases using native VS controls, have you asked in the Aforge forums about your memory issue?
    http://www.aforgenet.com/aforge/framework/

  • Acrobat XI Windows 7 - unable to (copy and) paste form fields to a different pdf.

    To maintain a consistent appearance and function in the forms I create for various departments, I copy a few form fields  (text, checkboxes) from an unrelated Acrobat PDF. Then I paste those fields into a different PDF document that I am making fillable.
    I do this because Acrobat does not allow setting a default for certain attributes when creating form fields, i.e. an unchecked scroll option, a default font other than Helvetica (in Acrobat 8, 9, and X). Plus it is time-saving to copy and paste fields that are the same in another PDF, like name, address, phone. etc.
    We just updated to Acrobat XI and Windows 7 and now I cannot paste copied fields onto a different PDF.
    Using "replace pages" is not applicable as I am pasting to an entirely different form and copying form fields with the settings I use. 
    Is this a glitch or is something new that was not in Acrobat 8, 9, and X?
    Also, question regarding this forum entry -  http://forums.adobe.com/message/5638333#5638333 - which is somewhat different from my current question.
    The PDF creator could not paste copied fields on other pages of the same PDF. Was this ever resolved so that copy and paste worked as it has for the last 3 versions of Acrobat?
    Thanks!
    Joanie

    Gilad:  You're right: when the fields are different, such as a checkbox and a text field, and you try to title them the same, Acrobat gives you a message. I received no messages, the field names are not the same or I missed one and Acrobat is no longer messaging about it.
    My question is different. Acrobat XI will not let me paste any field copied from a different PDF.  I've been doing that for 5 years in three different versions.  Maybe Acrobat XI has a new process for that, which I could not find in Acrobat help. Maybe it's because all forms now have extended rights automatically in Acrobat XI and there is another method to copy common fields to other PDFs.
    Any thoughts about the new Acrobat XI? It's different in many good ways, but different.
    Thanks for your ideas.

  • I was wondering can i install windows on my mac when i have downloaded windows form the internet and do not have a C.D.??

    I was wondering can i install windows on my mac when i have downloaded windows form the internet and do not have a C.D.??
    Because when i get to the part in Boot Camp Assistant that says Start Windows Installation it says u need a disc... is there no other way??

    Get the physical copy (disk) this will enable you to reinstall when (not if ) it messes up.
    Make sure to purchase acopy that is compatible with your OSX

  • Best way to port all Windows XP files, applicaitons and data form my PC over to iMac and how to run those Windows apps on Mac?ns on Mac?

    I have a Windows XP machine with apps, files and data.  I want to get all that over to my Mac, and also run those apps under Windows XP or even Windows 7 on my Mac.  Im wondering:
    1.  How best to get those files over to my Mac
    2.  How to run those apps and use my Windows based files/data on my Mac
    3.  How best to run Windows on my Mac....either partitiion my Mac's hard drive and boot up either Windows or MAC OS, or run some other program where I can easily switch back and forth form Windows to MAC OS, or perhaps get it all on an external hard drive, maybe partition that Windows/MAC OS and boot from that?
    Thanks!

    I agree you would benefit by using virtualizaiton software. Virtual Box is one alternative the commercial apps for doing virtualization are Parallels and VMWare Fusion which you also might be interested in for their support and updates.
    Also you may benefit by book marking and using:
    Mac 101 , Switch 101 & Find Out How Video tutorials
    For your MS Office apps then I'd STRONGLY recommend using the native Office For Mac versions, you can find these on Amazon for less than $100 and then you can run the apps natively rather than having to lean on MS Windows. Also for your Financial and Tax software you also may want to use OS X apps too, for example I used Quicken for over 20 years (PC mostly and some Mac) but switched to iBank. Also for tax software I have used Quicken's Turbo Tax, this also runs natively on OS X.
    In other words for your stated needs I don't see much reason to stay with MS Windows. You may have other considerations, if you do please state them, some may be real issues and some may be easily overcome.

  • How Do I create Windows Form file in VS and add the form to my VS project?

    C#, How Do I create Windows Form file in VS and add the form file to my VS project by using C# code?
    I like to create a Windows Form file into my VS Win Form project by using C#. I have the path and the file name.
    I need a Win Form with FileName.cs, FileName.Designer.cs, FileName.resx, and FileName (as you see it VS by adding a Win Form manually by using VS)
    Rune Brattas

    You cannot create a Form from code at run time. 
    For one thing, the user running your application will, almost certainly, not have  a copy of Visual Studio to hand with which to build anything.  (Not that you actually need 'Studio at all; Notepad and csc.exe are all you actually
    need), but that's another story).
    You can do this with an awful lot of pain, using the innards of the compiler from iside your own program, compiling the new Form's source code on the fly and then executing the resulting assembly within your application.  IMHO, that's a simply terrifying
    prospect especially as the code you will be compiling will be on someone else's machine and over which you will have absolutely no control.  If you're lucky, they'll spell something wrong and it won't compile.
    The "usual" way to do this sort of thing is to create additional, "plug-in" forms as library assemblies and have your program load and execute these at run-time. 
    Regards, Phill W.

  • Problem in adding "TableLayoutPanel" control array type functionality on windows form dynamically using drag and drop

    Environment: -
     (Application Machine)
    OS Name             : -
    Microsoft Windows 7 Professional/XP SP2/SP3            
    OS Bit Version      : -
    32 Bit                     
    Application Name: - Designer.exe                                  
    IDE                  
        : - Visual Studio 2008                        
    EXE Application development: -
    VB. Net
    Application Type: -
    Application “Designer.exe” was designed in vb6.0 and now, it has been upgraded to Visual Studio 2008 and it works properly.
    Product Description: -
                 We have an application Designer.exe, which is used for designing “Forms”.
    It has menu option with following option like Panel, Text Box, Combo Box, Button etc. We drag any of this menu items and place it to form.
    Requirement: -
    We have
    critical requirement in product. In Designer.exe, we need to align form margin, while we increase or decrease window. And for that we have searched that 
     “TableLayoutPanel” components can be helpful.
    Problem description: -
    Earlier code was in vb6.0, now it has upgraded to Visual Studio 2008. In vb6.0, we have used control array for memory utilization with Combo Box, Group Box, and Text
    Box etc.
    But, for alignment we have to use “TableLayoutPanel”
    control array type functionality on form.
    Code Snippet: - For earlier designing component e.g. Frame
    'Required by the Windows Form Designer
    Public WithEvents Frame1 As Microsoft.VisualBasic.Compatibility.VB6.GroupBoxArray
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    Me.components = New System.ComponentModel.Container
    Me.Frame1 = New Microsoft.VisualBasic.Compatibility.VB6.GroupBoxArray(Me.components)
    CType(Me.Frame1, System.ComponentModel.ISupportInitialize).BeginInit()
    . Kindly suggest approach for implementing requirement.
    Kindly help us to complete the requirement. I will be really
    thankful for any assistance.

    Hi S.P Singh,
    Welcome to MSDN.
    I am afraid that as Renee Culver said, these forums donot support VB6, you could refer to this thread:
    Where to post your VB 6 questions
    You could consider posting this issue in these forums below:
    These forums do not support Visual Basic 6, however there are many third-party support sites that do. If you have a VB6-related question please visit these popular forums:
    VB Forums
    VB City
    Thanks for your understanding.
    Best Regards,
    Youjun Tang
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How to turn of menu bar and window decoration of Forms 11g Rel2?

    According to Forms documentation, one can turn off menu bar and window decoration.
    How can that be done?.
    Best regards, Luis ...:)=

    From the documentation (Forms Deployment Guide), see Section 3.4.3. Refer to "guiMode"
    http://docs.oracle.com/cd/E38115_01/doc.111210/e24477/basics.htm#BABGEGBC

  • I am thinking of buying a iPad but my main desktop machine uses Windows 7 and MS Office.  How easy or difficult is it to transfer data files between the iPad and Windows?  Are there obvious problems or the need for some form of conversion programs?

    I am thinking of buying a iPad but my main desktop machine uses Windows 7 and MS Office.  How easy or difficult is it to transfer data files between the iPad and Windows?  Are there obvious problems or the need for some form of conversion programs?
    Many thanks for any advice.
    David

    You don't need conversion programs, iTunes can copy most of your content over to the iPad via the file sharing section, and some apps also support Dropbox, email attachments, transfer via your wifi network. There are a number of apps that you can get that support Microsoft office file (microsoft don't make an app versions of their software) e.g. from Apple there are Pages (word support), Numbers (excel) and Keynote (powerpoint), and from third-parties there are apps such as Documents To Go and QuickOffice HD

  • Compatibility forms 6i and Windows Server 2008

    Hi,
    We want to change our Server from 2003 to Windows Server 2008 64bits.
    My question is : is there a compatibility between Oracle forms 6i (our application) and Windows Server 2008 ?
    Will the migration be successfull, or will we have some bugs?
    Thks for your help.
    O.

    YES. It worked perfectly for me, you'll have to use oracle 8/8i lite though.

  • Forms 6i and Windows 8 64-bit

    Hi all.
    Are there any known issues using froms 6i on Windows 8 64-bit?.
    Other than this link: http://windows7bugs.wordpress.com/?s=6i+windows+8
    Any other feedback someone could provide ...?
    Regards, Luis ...:)
    Hi any feedback on this issue????
    Edited by: myluism on 29-may-2013 6:07

    APEX is not the only framework out there; there are others. In the end it won't hurt if you put stuff on the database as you will have the benefit of using it from different client tools of your like. Of course moving away from forms means a rewrite. You have to weigh the up and downsides yourself.
    You don't need to move away from forms if you don't see a need for it. However IMHO the installation type of forms 11g with 2 Managed weblogic Servers and one AdminServer running a total of 3 Servlets (plus EM and the weblogic console which are not needed 95% of time) and consuming a total of 3 GB memory makes it completely unusable for small to middle-sized installations. At least we have difficulties to explain to small customers why their application server needs to be twice as big as their database. And all this just because of weblogic which is basically bored as the whole work is done by the forms/reports runtimes which are seperate C-programs. And of course if you are running forms on windows you have the forms session limit imposed by the limitations of the desktop heap on windows platforms (read MOS note 187455.1) which makes the thinking of a "big" forms installation on one server also obsolete at least for windows platforms, and having forms and reports seperated in different managed server has basically no advantage.
    So for planning the future of your application I guess you should consider this too. Because of the whole confusion middleware blah forms won't move away from weblogic even if it means breaking nuts with a sledgehammer, and as far as the installation type goes this won't change either (filed a enhancement request for a small impact installation with support which got rejected). If you are serving small to middle sized companies better think twice if forms is the correct tool to use.
    Anyway; did you try with the latest patches for forms as mentioned earlier?
    cheers

  • Connectiong Visual Studio 2010/2013 to SQL Database and Running VS Windows Form App in the Windows Azure Cloud

    Hi, good day
    Im going to have a little presentation before I finished my OJT and the topic that was given to is cloud computing. One of the task I need to do is to set up an application where in it can run and access real time on the "cloud". Now my prob is
    I already have windows azure account, made my database, BUT don't know how to connect it to my Visual Studio 2010/2013 (which is more preferable?), and if I ever connect it when my Windows Form is made can it run on the cloud also, how? Please help. Thank
    you so much.
    PS: I will be discussing this with people who doesn't know much about computing can you send me tips what to discuss? Double Thank You. :)

    Thank you for the help.. Another thing can I run my Windows Form App also on the cloud? Like if I present is it possible that the application that I will be doing can be uploaded and accessed on the cloud by the audience and can be used by many at the
    same time? Can you tell me how? Or give me a source how to do it? I downloaded the azure tools but I don't how to use it. I checked and tried activating and fixing my IIS and enabling support for ASP but still nothing, when I try to do cloudservice it says
    "get azure tools" even though I already have it installed in my laptop, and when I try to right click and upload the project to azure I don't see the usual option 'Upload to Microsoft Azure'. My app is a simple phonebook app with add, edit, delete and search
    function. Thanks again..

  • Forms Code-Validation between 10g AS and windows

    i have a doubt as to what will be the forms code to validate between 10g AS and windows. This code will be used for in the case of windows authentication working between 10g AS and windows.
    I hope, my question is clear. Please help in solving the doubt.
    Regards.

    my doubt is that what will be the forms code to validate between 10g AS and windows. This code will be used for in the case of windows authentication working between 10g AS and windows. I mean to say that the code will have to be given in the my login form to validate that the user & password entered in my login-in form is the Windows user & password, if it is correct, it will allow to go to the next screen but if it is not correct, it will not allow to go to the next screen.
    regards.

  • Forms Authentication Error: User '' does not have required permissions. Verify that sufficient permissions have been granted and Windows User Account Control (UAC) restrictions have been addressed

    I created a custom security extension following the steps listed in the Readme_Security Extension Sample. It works fine if I login as the user that is specified AdminConfiguration section of the rsreportserver.config file but if I
    log in as another user, I get this error: User '' does not have required permissions. Verify that sufficient permissions have been granted and Windows User Account Control (UAC) restrictions have been addressed.  I've added the user to both System Administrator
    and System User roles to try to get it to work but still no luck.
    Does anyone know how to fix this?
    Thanks.

    Hi MetronM,
    The issue is due to that user have no permission to access the report server. In report manager, Reporting Services includes predefined roles that we can assign to users and groups to provide immediate access to a report server. Each role defines a collection
    of related tasks.
    You can refer to the following steps to assign corresponding role to the user.
    Open report manager.
    Click “Folder Setting” button. 
    Click “New Role Assignment” icon.
    Type the user name and select the corresponding role.
    There is an article about Granting Permissions on a Native Mode Report Server, you can refer to it.
    http://technet.microsoft.com/en-us/library/ms156014.aspx
    Regards,
    Alisa Tang
    Alisa Tang
    TechNet Community Support

  • OWB and Windows 7

    Hi, we're trying to get OWB running under Windows 7. Right now, we're constrained on staying with OWB 10.2.0.4 (or possibly 10.2.0.5 if upgrade is needed). Anyone had luck getting this to run? Maybe by using the special Vista version or something?
    p.s. Oracle support says OWB 10.2.xxx will not (ever) be supported on Windows 7 - but we've got to try something....
    I'd try this out myself - but I don't have access to Windows 7, it's on a production control person's machine we need to get this working.
    Thx,
    Scott

    I'm running 64 bit Windows 7 and OWB 11gR1.
    OWB 11g won't work properly when installed natively - there are far too many places where exceptions are trapped and ignored - hiding errors.
    OWB works fine when installed in a 32bit XP VM.
    If you are on Windows 7 Business or Ultimate, you can install Windows Virtual PC and XP mode.
    Install in a VM and it works fine. Windows 7 actually has some nice integration features to make this layering of Operating Systems a little more transparent.
    I think the problems relate to the 64 bit java vs the 32 bit java and the crappy exception handling that went into OWB.
    A well written java program (see SQL Developer) shouldn't have too much difficulty in the port to 64 bit.
    I'd wager that OWB will never make it to 64 bit. Some form of the future merged OWB and ODI will make it's way to 64 bit Windows.

Maybe you are looking for

  • Applying a CSS style to an existing web page

    Hi all. I have recently updated the look of one of my web pages in my site. I'm looking to update the look of the other pages in my site as well to the same style/look. I have a CSS style saved as  "main layout" that I would like to use to apply the

  • Passing a variable into HTML to play a Flash file

    I'm trying to create a simple SWF file that can receive the name of a FLV file in the HTML file and play it since I have many FLV files.  Basically using the technique of FlashVars.  I've set the contentPath/source in the components to be blank, and

  • Character widths in JTextPane

    Hello everybody I write a WYSIWYG Report-Editor. My Problem is that the character-widths in the Editor is different to the Output (rtf,pdf). For Exaple in the Editor i can write 45 w's (Arial,plain,11) in one Line an in the Output is was 57. With Tim

  • IP commmunicator

    I'm running v.2.1 for the ip communicator. Every since I upgraded from 2.02 I have had a lot of complaints from users stating that they can't dial 800#. all other numbers work. If I un-check the "Optimize for Low Bandwidth" it works. user are able to

  • Version 4.3.3 (8J2) not compatible with Bose docking station

    I recently update my new ipod touch to version 4.3.3(8J2) and it is no longer compatible with my Bose docking station, no sound coming out from the speakers but able to recharge the battery). How can I go back to plain version 4.3 or get a compatible