views:

28

answers:

1

Newb here.

I am instantiating the class below from a Silverlight page's code-behind.

I am trying to understand why the threads that spin off (the loadoperation and the worker) successfully raise the Selected event on the class when their completed events fire, but the Select event on the method call (in this case the constructer) itself is always null and therefore cannot?

Is there a way to raise the event on the method call itself?

Thanks!

    public EventTest()
    {
        if (1 != 1) //for test purposes
        {
            IPWorxDomainContext ctx = new IPWorxDomainContext();
            loadOperation = ctx.Load(ctx.GetTradeMarkRegistryListingsQuery());
            loadOperation.Completed += new EventHandler(loadOperation_Completed);
        }
        else 
        {
            if (Selected != null) //always null
            {
                Selected(null, new EventArgs());
            }

            worker = new BackgroundWorker();
            worker.DoWork += new DoWorkEventHandler(worker_DoWork);
            worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            worker.RunWorkerAsync();
        }
    }
A: 

If you examine the code that is calling EventTest you'll find that the Selected event is being assigned after the call. Hence during EventTest the event is null. The completed events occur later after EventTest has completed and the SelectedEvent has been assigned.

AnthonyWJones