In my C# win form project, I read some data by web service. It takes a few time, so I have a thread for reading like this:
System.Threading.ThreadPool.QueueUserWorkItem((o) =>
{
SMSCenter_RecievedMessages = (new SMSCenterGetMessages()).getMessages());
this.BeginInvoke(new Action(() =>
{
if (SMSCenter_RecievedMessages != null && SMSCenter_RecievedMessages.Length != 0)
{
// some code
}
}));
});
after 2 days running, some time I get this exception:
Null Reference Exception was unhandled : Object Reference Not set to an instance of an object.
Is it possible that before creating a new of object, getMessage()
function is accured? Because I did it by thread. what is the wrong by this code?
Thanks for any helping?