In a thread, a file is being opened, closed and disposed continuosly. Does this cause an issue ?
Here is the code
StreamWriter file1 = new StreamWriter(filepath4, true);
for (int i = 0; i < ChannelValueForTcp; i++)
{
file1.WriteLine(data[i]);
}
file1.WriteLine(data[data.Length-1]);
file1.WriteLine(data[data.Length - 2]);
file1.Close();
file1.Dispose();

Please help I am stuck. (This comes up randomly we are trying to run the code for 8 hours continuously.)
Edit:
No no other thread works or does anything associated with this file. It is being used only here. There are other threads running, which are giving the same error but randomly after 45 minutes - 5 hours of testing.
Here is the c code. Please download it
[DllImport("ConsoleApplication2.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern int main_c();
public string[] tcp(string peer, int port)
{
int i = main_c();//the c code writes to a file called akash.txt and returns = 0 if it is successful. Then I read the file and do some functions on it.
if (i == 0)
{
StreamReader objReader = new StreamReader("akash.txt");
unsafecode?