I am getting an assert occasionally in the following
void CFile::Write(const void* lpBuf, UINT nCount)
ASSERT_VALID(this); ASSERT(m_hFile != (UINT)hFileNull);
Basically This call is from another thread (worker thread)(thread B) to write to a file and this thread does not initially create the File Object . The file object is created by the main thread (thread A ).
The above assertion happens when B tries to write to the file after A has created the file .
I have tried to put a critical section where the common function to write to the file is called but still I see the assert .
Could this be because of my thread not being able to access MFC cFile Object correctly
Also this happens occasionally 2out of 10 times .
I also see that the file is finally getting written with contents for both thread A and B but this ASSERT is worrying me .
It's likely that thread A had not yet actually opened the file, or at least assigned m_hFile to the file handle, before thread B runs. Since there is an OS call, it is very likely the open operation is triggering a sleep operation which, in turn, is causing thread B to run if it has been created by that point.
I suggest not creating thread B until thread A has opened the file. An alternative is to have thread B wait on an event that will be signalled once thread A has opened the file.
A critical section should be used for read/write/close operations, but are a potential problem here since thread B could get it's time slice before thread A even enters its critical section to open the file.
Another option to look at is for thread B to open and close the file.
Also note that when you close the file, thread B must either be terminated (wait on it's handle, then close the file) or should check if the file handle is valid before performing the operation.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
I will change an the content of a node in a XML-File. It is no problem, to get the specific node and its content. But to change the content of the Node I have to use the function "InsertData" from the class IXMLDOMText. Therefor I have to initialize the IXMLDOMTextPtr. But every time I try this, I get the error message, that the left part of ->"Query Interface" has to point to a class... So what's wrong with that?
Below the pasted code to make it a little bit more understandable.
Put a static control on your window/dialog, and associate a CStatic member variable with it using ClassWizard. Use SetTimer() to create a timer event every 300000ms (five minutes). In the event handler for the timer, call LoadImage() to load the .bmp file from disk. Using the returned handle, then call CStatic::SetBitmap() to associate the new bitmap with the static control. Make sense?
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
i had made the class in VC++.NET which contain the API's now i want to use
this class in the C#.NET how to do that whether make the cllas library(DLL) of that class and
then use of simple only use the class.
i had not used those api's in the C# bcos it is difficult to get the help of