I raise the event Itemselected using 'view.Picker.Presenter.Raise(x =>
x.ItemSelected += null, this, e)' which calls ViewerDoWork on a
background thread (using BackgroundWorker object) but variables of
parameter e passed to ViewerDoWork give error 'Unable to evaluate
expression because the code is optimized or a native frame is on top
of the call stack' when viewed in the debugger. When I try to do the
assignment 'e.Result = Visibility.Collapsed' my program crashes. The
only way to fix this is to add the Thread.Sleep at the end of Main().
Does anybody know why this is happening and how to fix it?

Thanks you in advance for your help.

Jay

void Main()
{
    ISimpleViewerView view = this.mock.DynamicMock<ISimpleViewerView>
();

    new SimpleViewerPresenter(view);

    SetTimeEntityTypeSelectedEventArgs e = new
SetTimeEntityTypeSelectedEventArgs();

    // Raise ItemSelected event
    view.Picker.Presenter.Raise(x => x.ItemSelected += null, this, e);

    //Thread.Sleep(60 * 1000);
}

internal class SimpleViewerPresenter : ISimpleViewerPresenter
{
    public ISimpleViewerView View { get; set; }
    private readonly BackgroundWorker viewerWorker;

    public SimpleViewerPresenter(ISimpleViewerView view)
    {
        this.View = view;
        this.View.Picker.Presenter.ItemSelected +=
this.NewItemSelected;

        this.viewerWorker = new BackgroundWorker();
        this.viewerWorker.DoWork += this.ViewerDoWork;
        this.viewerWorker.RunWorkerCompleted +=
this.ViewerWorkerCompleted;
    }

    private void NewItemSelected(object sender,
SetTimeEntityTypeSelectedEventArgs e)
    {
        if (!this.viewerWorker.IsBusy)
            this.viewerWorker.RunWorkerAsync(e);
    }

    private void ViewerDoWork(object sender, DoWorkEventArgs e)
    {
        e.Result = Visibility.Collapsed;

        var arg = e.Argument as SetTimeEntityTypeSelectedEventArgs;
        if (arg == null)
            return;
    }
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Rhino.Mocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rhinomocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to