ScriptBlock to Delegate casting...?

Discussion in 'Scripting' started by Nick, Feb 16, 2006.

  1. Nick

    Nick Guest

    I guess that I don't fully understand the ScriptBlock-to-Delegate casting
    system...I'm trying to create a WPF window from MSH, and then ShowDialog()
    it, but apparently I need to do this from an STA thread, so I'm trying to use
    Dispatcher.Invoke() to do this:

    $w.Dispatcher.Invoke("Normal", { param($window); $window.ShowDialog(); }, $w);

    This command throws an exception that it can't convert the scriptblock to a
    delegate. I've tried using Reflection.Emit to define my own delegate with
    various matching signatures, but it always refuses to cast. If I try to cast
    to EventHandler, though, it works fine. What am I doing wrong?

    [howell.retrievewindow]{ param($window); $window.ShowDialog(); } # throws
    exception
    [eventhandler]{ param($window); $window.ShowDialog(); } # doesn't


    Thanks,
    Nick Howell
     
    Nick, Feb 16, 2006
    #1
    1. Advertisements

  2. Nick

    Nick Guest

    Thanks a lot! That solved *that* problem, although now I'm having trouble
    getting the WPF window to work, but that's a question for the Avalon board.

    Nick

     
    Nick, Feb 19, 2006
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.