|
no, not from inside the thread... The creator of the thread, kills its created thread.
<br />
while (!m_dwBytesRead && (nRetries < 2600))<br />
{<br />
m_pReadThread=AfxBeginThread(ReadThread, this, THREAD_PRIORITY_NORMAL);<br />
<br />
nRetries++;<br />
::Sleep(600);<br />
<br />
if (!m_dwBytesRead)<br />
{<br />
}<br />
}<br />
There is no spoon.
|
|
|
|
|
|
I wish the creator of the thread kill his created thread:
while (!m_dwBytesRead && (nRetries < 2600))<br />
{<br />
m_pReadThread=AfxBeginThread(ReadThread, this, THREAD_PRIORITY_NORMAL);<br />
<br />
nRetries++;<br />
::Sleep(600);<br />
<br />
if (!m_dwBytesRead)<br />
{<br />
}<br />
}
There is no spoon.
|
|
|
|
|
ok, i so repost my question :
don't SendMessge() work with the correct argument ? (i don't remember which, but it might be something like WM_KILL or WM_END)... of course, sent to the correct thread, ie. m_pReadThread
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
no, the owner of the thread is not a window. the owner of the thread is a CObject derived class. There must be a way for the owner of the thread to kill its own created thread without condition.
There is no spoon.
|
|
|
|
|
where did you see that SendMessage() was a member of CWindow or CDialog or i don't even know what else... there's a global one ...
but if you don't want (and you ahve the right to), don't do it ...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi,
I have explained the purpose of the thread a little bit late. So I repeat the purpose:
the thread just call the ReadFile API. So, if nothing comes, the ReadFile API waits indefinitly. Thus, I can't use OVERLAPPED because it is not supported by the driver. So, I can use only synchronous IOs in my thread. The way I want to handle the ReadFile timeouts (it's not serial IOs) is to use the ReadFile API in a thread and the caller create and destroy the thread after an amount of time while nothing comes. If something comes, the thread finish itself naturally.
I can create the thread, but I don't know how I can destroy the thread FROM the caller. not inside the thread itself.
so, you understand, that if I try to exit FROM the created thread, once it waits for data from the ReadFile , I can wait forever and the thread never exits because it is blocked by the ReadFile API. That's why I need to kill the thread from outside without condition. see what I mean?
thanks.
There is no spoon.
|
|
|
|
|
Hain Tox!!!
Actually Worker thread don't have any message handlling capability! So how it's going to handle SendMessage(...) Thread.
Same thing is possible with UI threads where you can use PostThreadMessage(..)to send message to the thread!
[Vote One Here, Complete my Survey....]
Alok Gupta visit me at http://www.thisisalok.tk
"I Think Believe this Will Help"
|
|
|
|
|
why can't you use global flag and in your child thrad put the code in a loop,like this(Exit is boolian veriable from CTestDlg class):
void CTestDlg::OnTest()
{
while (!m_dwBytesRead && (nRetries < 2600))
{
Exit = false;
m_pReadThread=AfxBeginThread(ReadThread, this, THREAD_PRIORITY_NORMAL);
nRetries++;
::Sleep(600);
if (!m_dwBytesRead)
{
Exit = true;
}
}
}
UINT ChildThrad(LPVOID lpvoid)
{
CTestDlg *dlg = (CTestDlg *)lpvoid;
while(!dlg->Exit)
{
}
return 0;
}
|
|
|
|
|
the thread just call the ReadFile API. So, if nothing comes, the ReadFile API waits indefinitly. Thus, I can't use OVERLAPPED because it is not supported by the driver. So, I can use only synchronous IOs in my thread. The way I want to handle the ReadFile timeouts (it's not serial IOs) is to use the ReadFile API in a thread and the caller create and destroy the thread after an amount of time while nothing comes. If something comes, the thread finish itself naturally.
I can create the thread, but I don't know how I can destroy the thread FROM the caller. not inside the thread itself.
Best regards.
There is no spoon.
|
|
|
|
|
If you want to kill off a thread, you could mention how to do it in VB .... oops sorry I am still in April Fools day mood!
Seriously, you can call (but never advised because of its sheer brutality)
::TerminateThread(m_hThread,0);
|
|
|
|
|
I just wanted that at last, you understood my needs
and now, I have memory leaks,
There is no spoon.
|
|
|
|
|
Memory leaks because you called TerminateThread(), who would have thought.... Just kidding.
But of COURSE you have memory leaks, since your thread did not terminate 'normally'.
You really ARE dealing with a poorly designed driver, aren't you? They should have provided at least a 'is data available' call for you or something. Is there truly no way to set any kind of timeout in case there is no data? Most device drivers will just return that there are no bytes to read instead of hanging your thread up.
Part of your leak might be from the CWinThread object returned from the AfxBeginThread call. When you assssinate your thread, you might want to at least delete the CWinThread object data.
I truly encourage you to seek another driver, or at least a design option that does not force you to continually start and kill threads in this manner.
Good luck!
|
|
|
|
|
Hi,
When I delete the thread from the m_pThread (CWinThread*) it crashes. So, I am using the simple Win32 API function CreateThread and TerminateThread and there is no memory leaks. Why doing complex as we can do simple?
Indeed, the driver is poorly implemented. It's a USB driver for HP calculators (shipped by HP) and it does not handle correctly the overlapped IO (the system crashes when I use overlapped IOs), if it would have handle them correctly, of course, overlapped IO would have been much more simple. But now, with this brutal algorithm of calling ReadFile in a thread and kill the thread after an amount of time and repeat the operation until something comes works fine now But I'm agree that overlapped IO should be the best choice. Of course, using overlapped IOs, is the first idea that came in mind.
There is no spoon.
|
|
|
|
|
Hi,
When I delete the thread from the m_pThread (CWinThread*) it crashes. So, I am using the simple Win32 API function CreateThread and TerminateThread and there is no memory leaks. Why doing complex as we can do simple?
Indeed, the driver is poorly implemented. It's a USB driver for HP calculators (shipped by HP) and it does not handle correctly the overlapped IO (the system crashes when I use overlapped IOs), if it would have handle them correctly, of course, overlapped IO would have been much more simple. But now, with this brutal algorithm of calling ReadFile in a thread and kill the thread after an amount of time and repeat the operation until something comes works fine now But I'm agree that overlapped IO should be the best choice. Of course, using overlapped IOs, is the first idea that came in mind.
Thanks to all of you for the help
Best regards.
There is no spoon.
|
|
|
|
|
See here.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
Hi
I am trying to add a dialog to an existing project.
I add the resource file .rc then add the dialog and double click on it an the class creator/wizard thing appears so I enter the class name.
Now I try to add a button and test it by adding a show message to it's event handler.
The problem is, it doesn't compile and the error is:
IDD_DIALOG1 = undefined
enum {IDD = IDD_DIALOG1};
Help!
|
|
|
|
|
why did you copy the .RC file ???
as far as i know, when you create a dialog, you set its ID. the same when you add a button to the dialog... then, you can associate an event handler to that ID...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
toxcct wrote:
why did you copy the .RC file ???
I created the .rc file i.e. added it to the project
then the dialog is added as a child of the .rc file
Am I doing this all wrong?
Can you step me through what you would do to add a dialog with a button?
Cheers
|
|
|
|
|
|
TheProffessor wrote:
I am trying to add a dialog to an existing project.
Exactly how did you do this?
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
|
|
|
|
|
#include"resource.h" didn't work
still get the same error
error C2065: 'IDD_SHUTDOWN' : undeclared identifier
|
|
|
|
|
|
ThatsAlok wrote:
Then Check wheather IDD_SHUTDOWN is defined in Resource.h or not!
It wasn't defined! But now I get lots of errors saying that everything is already defined in a .obj file.
????
|
|
|
|
|
Hi,
How can implement Windows Explorer-style folder tree view?
Would any one give me a hint?
Regards.
|
|
|
|