多线程中对文件进行写操作

我的多线程部分程序是这样的:
UINT ClientThread(LPVOID pParam)
{
EnterCriticalSection(&cs);
Cw_dispctrlDlg dlg=(Cw_dispctrlDlg)pParam;

while(true)
{
     ……
     ……
     dlg->file_net.Open(dlg->str_file_netpath, CFile::modeCreate | CFile::modeNoTruncate | CFile::modeWrite | CFile::typeText);
     dlg->file_net.SeekToEnd();
     dlg->file_net.WriteString(tmp1);
     }
     LeaveCriticalSection(&cs);
return 0;

}
调试时,程序运行到dlg->file_net.Open时就会出错,不明原因,请大神指点!急!谢!

线程中不要直接操作UI对象,可以PostMessage发送消息给主线程,让主线程再操作UI