this error has appeared to many of the users, but in my case Visual studio seems to be pointing on a string object. My code is the following:
protected delegate void DPrint_To_LogScreen(string Text, bool NewLine);
protected void Print_To_LogScreen(string Text, bool NewLine)
{
if (InvokeRequired)
Invoke(new DPrint_To_LogScreen(Print_To_LogScreen), new object[] { Text, NewLine }); // exception thrown here from the Text string
else
{
LogScreen.AppendText(Convert.ToString(DateTime.Now) + " -> " + Text + (NewLine ? System.Environment.NewLine : ""));
if (Log_Screen_File == null)
{
Log_Screen_File = new StreamWriter(@"Global.log", true);
Log_Screen_File.WriteLine(Convert.ToString(DateTime.Now) + " -> " + Text);
Log_Screen_File.Close();
}
else
{
lock (Log_Screen_File)
Log_Screen_File.WriteLine(Convert.ToString(DateTime.Now) + " -> " + Text);
}
}
}
I generally want to call function Print_To_LogScreen from different places and threads.
i expected that the "if (Log_Screen_File == null)" statement would do the job (and in the general case it works) but now the exception is thrown by the Text object on the invoke command!!
Is this even possible or Visual Studio means the output file? And if so why the "if (Log_Screen_File == null)" does not work?
thank you