I’ve got a method which gets called frequently by different treads. Sometimes I get an AgrumenNullException when ThreadPool.QueueUserWorkItem(display(angebot), null); gets called, stating that the parameter callBack (the first parameter) is null.
What am I doing wrong?
public class ai : UserControl
{
//...
public void Display(Angebote angebot)
{
lock (_syncObj) { _current = angebot; }
ThreadPool.QueueUserWorkItem(display(angebot), null);
}
private WaitCallback display(Angebote angebot)
{
// doing something
}
//...
}
The
ThreadPool.QueueUserWorkItemwill do the work as defined in theWaitCallbackdelegate returned bydisplay(Angebote). I would surmise that yourdisplaymethod sometimes returns null.Is your intent to execute
display(angebot)in the background thread, or does that method discern what method should be executed?If you’re thinking that your display method should be executing in a background thread:
Then your code should look like:
EDIT: If it’s the latter where
displayis figuring out what background thread to execute, then perhaps you have something looking like this:But since you haven’t posted that code, I’m not sure. In this case, returning
nullis invalid forThreadPool.QueueUserWorkItem.