|
I have a thread that plays a sequence of images. In the CDocument I handle controls to pause/play using events and boolean variables. I chose start the thread inside play() function. The way I handle pause() I don't care if the thread is there or not. However if the user presses play again, I don't want to start another thread, I want to continue the previous one.
I have the option of making a thread that runs for the life of the CDocument...but wouldn't that be wasteful when it sits there and waits on pause forever after a single play.
|
|
|
|
|
Also I should clarify currently the thread goes through the sequence of images and quits. So next time inside play() I need to know whether to resume the current thread or start a new one.
|
|
|
|
|
See here for details on how to properly pause and stop threads.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
Yes, that's what I use. Taken from the site:
<br />
while(running)<br />
{ <br />
if(paused)<br />
switch(::WaitForSingleObject(event, time))<br />
{<br />
case WAIT_OBJECT_0:<br />
break;<br />
case WAIT_TIMEOUT:<br />
continue;<br />
}<br />
} <br />
except instead of while(running), I have a for loop from 0 to numImages.
|
|
|
|
|
Budric B. wrote:
but wouldn't that be wasteful when it sits there and waits on pause forever after a single play.
Not neccessarily. Or at least I wouldn't think so if you're using WaitForSingleObject() to do the "waiting" and not a busy wait while loop.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
|
|
|
|
|
Jim Crafton wrote:
...if you're using WaitForSingleObject() to do the "waiting" and not a busy wait while loop.
Correct. WaitForSingleObject() uses no CPU time while waiting for the object state to become signaled or the time-out interval to elapse.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
AfxBeginThread returns the pointer of the created thread CWinThread.
Using BOOL GetExitCodeThread( HANDLE hThread, LPDWORD lpExitCode); you can get the status of this thread (STILL_ACTIVE if it's not terminated).
Marc Soleda
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
Hi,
I have developed real time file monitoring using Device driver ( with .sys & .vxd file), if i have changed the driver name and file name, i got error message
" Overlapped I/O operation is in progress".
can u help me?
Regards,
Inbha.
|
|
|
|
|
If call function and I want that function work not more than 3 sec.
how can force to softly exit from it if 3 sec expires.
Function not in my code I need somthing similiar to SendMessageTimeOut(...)
|
|
|
|
|
Alex_Y wrote:
Function not in my code I need somthing similiar to SendMessageTimeOut(...)
Where's it? In a library? in another process?
Marc Soleda.
... she said you are the perfect stranger she said baby let's keep it like this... Tunnel of Love, Dire Straits.
|
|
|
|
|
I actualy subclassing WinProc of ActiveX control. This is bad written control which I don't have source code. Now some times control recieve message from parent and opens socket connection. All my code freeze until ActiveX finish connection. I already make my own UI thread but still parent window calls child windows inluding activex directy via WinProc.
So I subclass ActiveX find bad message but I want timmed it. If it not done ReplyMessage(TRUE) and escape. I already tryied CallWinowsProc in sepparete worker thread. Doesn't help.
Thats my story.
Thanks for reply.
|
|
|
|
|
Start up a secondary thread that will call that function. Then call WaitForSingleObject() specifying 3000 for the timeout interval. If the return value is WAIT_TIMEOUT , then you know that the function is still running.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
I actualy subclassing WinProc of ActiveX control. This is bad written control which I don't have source code. Now some times control recieve message from parent and opens socket connection. All my code freeze until ActiveX finish connection. I already make my own UI thread but still parent window calls child windows inluding activex directy via WinProc.
So I subclass ActiveX find bad message but I want timmed it. If it not done ReplyMessage(TRUE) and escape. I already tryied CallWinowsProc in sepparete worker thread. Doesn't help.
Thats my story.
Thanks for reply.
|
|
|
|
|
I gone through MSDN it mentioned that CSyncsocket can be used as blocking as well in nonbloicking i,e synchronous and asyncronous both where we can get event notification
while CSocket can used in only blocking mode i.e synchronous mode.
I am not getting this explanation.
Can anybody somebody clear this more briefly
|
|
|
|
|
blocking sockets are sockets that are waiting for datas to be incoming... while nothing came to the recipient, it is blocked...
Asynchronous sockets can set a timeout, that means that when no packets entered after a certain duration, the receive function passes to the next instruction...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Thanx TOXCCT.
Could u explain this in terms of CSOcket and CAsyncsocket
according to MSDN CSyncsocket returns WSAEWOULDBLOCK but not CSocket.
As CSocket derived from CAsynsocket why we wold not override OnRecieve and called recieve method as its vitual
i think i am confused abt this operation
Anyone have good link abt this ...
|
|
|
|
|
read up on how recv/connect/send/etc work.
The basics are that they all perform some work on a socket handle (like attempt to read data from it, connect to the address, etc). When the function returns it will return some error code. Typically the error code is 0, -1, or some value that indicates how many bytes were processed. A -1 value is generally an error. The difference in CSocket or CSyncsocket is whether the socket can be set to blocking mode. Blocking mode means that the functions (recv/connect/send/etc )will NOT return until the function is complete. So if you attempt to connect to a blocking socking using connect() (or whatever it's called on CSocket), the connect9) function will NOT return until a connection has been established. Likewise calling recv in blocking mode will mean that the recv() function will NOT return until it has been able to extract the specified number of bytes from the socket.
If, however, you are using NON blocking sockets, then the functions will return immediately, and the return code will be -1. But it's not neccessarily an error. You need to call WSAGetLastError() to determine this. If this returns WSAEWOULDBLOCK, then this means that function completed OK, and it's potentially going to complete later on.
Typically you create a socket, connect, set it's blocking mode, and then start trying to send/recv from it (assuming this is a client socket). With an asnych, or non blocking socket, you'll need to poll it from time to time to see if you can get any data from it. Polling can be done using a crude while loop, sleeping for X n umber of milliseconds, and then calling recv or send, or you can use the select() function to query if the socket is ready to be read from or written to. Alternately you can even fancier by using overlapped IO, and if you're a complete masochist, migraqte to the madness that is IO completion ports.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
|
|
|
|
|
Thanx JIM for information
Typically you create a socket, connect, set it's blocking mode
how we set the blocking mode for that.
|
|
|
|
|
look up ioctlsocket - this is a BSD style socket function and it operates on a valid socket handle. I don't know what the equivalent with CSocket would be. You might use it like so:
void setBlocking( SOCKET s, const bool& isBlockingSocket )
{
unsigned long val = isBlockingSocket ? 0 : 1;
int err = ioctlsocket( s, FIONBIO, &val );
if ( err == SOCKET_ERROR ) {
err = WSAGetLastError();
}
}
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
|
|
|
|
|
ok JIM i go through that
Thax for for your explaination
|
|
|
|
|
I need to implement conditional drop source, which will behave differently if drop target is in the same process as a source. I override OnRenderData but can not figureout how can I get to the Drag Target from there.
VC++ and MFC
Thanks
Edit: Sorry, I made a mistake in original post. I do need to know Target, Not a source. I do create a source myself.
|
|
|
|
|
I thought you set it when you start to drag
OnDrag(...)
|
|
|
|
|
Alex, you are right. I made a mistake in original post. I do need to know Target. I edit orignal post.
Thanks
|
|
|
|
|
Derive your own class CMyTree : CTree
CMyTree::OnCreate
{
//REGISTER THIS WINDOW AS AN OLE DROP TARGET.
m_DropTarget.Register(this);
}
where m_DropTarget
class CDropTarget : public COleDropTarget // make him friend in CMyTree
{
public:
virtual DROPEFFECT OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
virtual DROPEFFECT OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
virtual BOOL OnDrop( CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point );
};
DROPEFFECT CDropTarget::OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
return ((CMyTree*)pWnd)->OnDragEnter(pDataObject, dwKeyState, point);
}
DROPEFFECT CDropTarget::OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
return ((CMyTree*)pWnd)->OnDragOver(pDataObject, dwKeyState, point);
}
BOOL CDropTarget::OnDrop( CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point )
{
return ((CMyTree*)pWnd)->OnDrop(pDataObject, dropEffect, point);
}
and finaly
DROPEFFECT CMyTree::OnDragOver(COleDataObject* pDataObject, DWORD dwKeyState, CPoint point)
{
if (pDataObject->IsDataAvailable(...))
{
UINT nFlags;
HTREEITEM hDropTarget = HitTest(point, &nFlags);
if(nFlags & TVHT_ONITEM)
{
SelectDropTarget(hDropTarget);
m_pTree->SelectDropTarget(hDropTarget);
// my custom message to my code process can I drop here or not
if(1 == GetOwner()->SendMessage(MYTW_CAN_DROP_HERE, 0, (LPARAM)hDropTarget))
return DROPEFFECT_MOVE;
else
return DROPEFFECT_NONE;
}
}
return DROPEFFECT_NONE;
}
Sorry if it lot. But this thing is not really obvious.
|
|
|
|
|