NULL REFERENCE EXCEPTION with this.Invoke

S

Safiiru no Baka

Here's my code (edited for clarity)
================================================================================
public Form1()
{
InitializeComponent();

notifyContentUpdated = new
contentUpdated(CallRefreshFields);

Thread myThread = new Thread(new
ThreadStart(MainWorkThread));
myThread.Start();

}

private void CallRefreshFields(bool dummyvariable)
{
this.Invoke(new EventHandler(RefreshFields));
}

private void RefreshFields(object sender, System.EventArgs e)
{
listBox1.Items.Clear();
listBox1.Items.Add("test");
}
================================================================================

notifyContentUpdated is a delegate as you might have guessed. I
subscribe to it to call CallRefreshFields which in turn "tries" to
Invoke RefreshFields. The error comes on the Invoke line, it gives me
the nullreference exception.

I'm at loss as to why, or what is exactly happening. Please help,
thanks.
 
D

Daniel Moth

Post the whole code (write a small repro)... the "edited for clarity" has
resulted in too much editing...

Cheers
Daniel
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Top