I'm currently having some problems with a method that throws an exception but I'm not sure why. The exception makes my application crash.
System.NullReferenceException: Object reference not set to an instance of an object.
at Myapp.AutoProcess.<ToRead>d__36.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__1(Object state)
at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback()
I run the method on a separate thread
Thread listenerThread = new Thread(() => ToRead());
listenerThread.Start();
The method that throws the exception looks like this:
private async void ToRead()
{
while (true)
{
if (this.toRead.Count != 0)
{
string protocol = this.toRead[0];
string[] temp = protocol.Split(',');
string message = temp[0];
string UserName = temp[1];
Process(message, UserName);
this.toRead.RemoveAt(0);
}
await Task.Delay(200);
}
}
It takes incoming messages from a List and filters out the Username and Message to send it to the Process method. I would appreciate if someone could help me out.
Note: The exception occurs about once a day running it on a Windows R2 2008 Server. Therefore I cant really debug it in Visual Studio