Q:

variable not set by background worker on first pass

I have an observer with a background worker. Lets say the observer has the following structure:
internal class Observer
{
    private readonly BackgroundWorker bw1;
    internal Object target;

    public Observer()
    {
        bw1 = new BackgroundWorker();
        bw1.DoWork += bw1_DoWork;
        bw1.RunWorkerCompleted += bw1_RunWorkerCompleted;
        bw1.WorkerSupportsCancellation = true;

    }

    private void bw1_DoWork(object sender, DoWorkEventArgs e)
    {
        e.Result = new object(); // Query to database
    }

    private void bw1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
    {
        target = e.Result as object;

        if (ChangedScannedValue != null)
        {
            ChangedScannedValue(_scannedValue);
        }
    }

    private String _scannedValue = string.Empty;
    internal delegate void OnChangedScannedValue(String scannedValue);
    internal event OnChangedScannedValue ChangedScannedValue;
    internal String ScannedValue
    {
        get { return _scannedValue; }
        set
        {
            _scannedValue = value;
            bw1.RunWorkerAsync(_scannedValue);
            //ProcessScannedValue();

        }
    }
}

I have another class listening to the event.
public partial class myControl : UserControl
{
    Observer _observer = new Observer();

    public myControl()
    {
        InitializeComponent();
    }

    internal void LoadData(Observer observer)
    {
        _observer = observer;
        _observer.ChangedScannedValue += _observer_ChangedScannedValue;
    }

    void _observer_ChangedScannedValue(string ScannedValue)
    {
        if (_observer.target != null)
        {
            // Do Stuff
        }
        else
        {
            MessageBox.Show("NO TARGET FOUND.");
        }
    }
}

The thing is. initially, after the background worker finishes, I get the message box "NO TARGET FOUND.", however immediatley after, it would //Do Stuff Debugging shows that the RunWorkerCompleted event fires twice. This only happens on the first change to scanned value, all changes afterwards work as desired.
Questions:
1) Why does RunWorkerCompleted fire twice?
2) Why is the target not updated on the first fire of RunWorkerCompleted

A:

You could try again with target being set in bw1_DoWork already, i.e.:
private void bw1_DoWork(object sender, DoWorkEventArgs e) {
    target = new object(); // Query to database
}

private void bw1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
    if (ChangedScannedValue != null) {
        ChangedScannedValue(_scannedValue);
    }
}

Eventually you may want to replace the BackgroundWorker by a simpler solution with ThreadPool. I'd suggest this:
internal String ScannedValue {
    get { return _scannedValue; }
    set {
        _scannedValue = value;
        ThreadPool.QueueUserWorkItem( (WaitCallback) delegate {
            target = new object(); // query database
            if (ChangedScannedValue != null) ChangedScannedValue(_scannedValue);
        } );
    }
}

