|
viperlogic wrote: what is the best way of killing a thread from outside the thread, i am using TerminateThread() but i dont think this is the best way??
Set a boolean varible depending on it state terminate the thread
|
|
|
|
|
what command do i use to kill the thread thou from outside the thread?
|
|
|
|
|
viperlogic wrote: what command do i use to kill the thread thou from outside the thread?
same, change the value of boolean variable from outside, which thread is checking from inside...
|
|
|
|
|
sorry, i dont understand, example please
thanks
|
|
|
|
|
viperlogic wrote: what is the best way of killing a thread from outside the thread...
See here.
"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
|
|
|
|
|
so i use the following to delete a thread from outside?? Does "delete pThread" call ExitThread??
switch(WaitForSingleObject(pThread->m_hThread, 3000))
{
case WAIT_TIMEOUT:
{
delete pThread;
break;
}
case WAIT_OBJECT_0:
{
// thread has terminated on its own
break;
}
}
|
|
|
|
|
viperlogic wrote: Does "delete pThread" call ExitThread??
No. At the point in which you are deleting pThread , the thread has already terminated. You are just cleaning up the CWinThread object.
ExitThread() is called from within the secondary thread, unlike TerminateThread() which is called from outside the secondary thread.
"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 think i have that working now.
A kind of related problem i have is with the code below. This is a part of the code the thread executes, if sucessful all is ok. this thread has a timeout of 3secs. A problem is that the ConnectServer call below takes 2minutes to complete if it cant connect. when this happens the below messagebox pops ups and then the program crashes. is it crashing because the code wants to "return" but there is nothing to return to as the thread has been already killed?? How can i modify it so that it wont crash. A message box doesnt have to be displayed either.
many thanks
<br />
hres = pLoc_test->ConnectServer(<br />
_bstr_t(L"\\\\"+strIP1+"\\root\\cimv2"),
NULL,
NULL,
0,
WBEM_FLAG_CONNECT_USE_MAX_WAIT,
0,
0,
&pSvc_test
);<br />
<br />
<br />
if (FAILED(hres))<br />
{<br />
char error_msg[64];<br />
sprintf(error_msg, "wmi_test: Could not connect. Error code = 0x%x", hres);<br />
MessageBox(error_msg , "Error" , MB_ICONERROR | MB_OK);<br />
<br />
pLoc_test->Release(); <br />
return; <br />
}<br />
|
|
|
|
|
Since you are using WBEM_FLAG_CONNECT_USE_MAX_WAIT , why not set your WaitForSingleObject() call to also wait for 2 minutes (or a little more)?
"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 am scanning alot of hosts with this app, waiting 2mins for every host would take for ever to scan the network, hence i use the thread timeout of 3secs
i just read about _endthread and it appears to work so far. is this a proper solution?
|
|
|
|
|
viperlogic wrote: i am scanning alot of hosts with this app, waiting 2mins for every host would take for ever to scan the network, hence i use the thread timeout of 3secs
I did something very similar to this in a ping-type application. For each machine that I was going to ping, I just created a secondary thread and put the ping-related code in it. Given that the machines each responded in their own time, the threads all completed at different times; some were instantaneous while others took a lot longer. If your UI has some sort of listbox or list control for these machines, give them a default status of "Establishing connection. Please wait...". When that machine's thread terminates, replace the default status with what actually happened.
viperlogic wrote: i just read about _endthread and it appears to work so far. is this a proper solution?
Not unless you also used _beginthread() . Regardless, it is called from within the secondary thread. Terminating a thread from within itself is vastly different than terminating a thread from some other thread.
"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 am implementing a Drag and Drop operation on a TreeView. I've supplied a bitmap to my tree and it draws wonderfully.
Now, when the user begins dragging - I call TreeView_CreateDragImage ... and for the most part, it works except that the dragging image (a folder) overlaps the textual part of the drag so that when you are draggin and move the mouse around, you can't see the first few characters of the TreeView node's text in the dragging image.
I can't see how to affect this. Are my bitmaps too large? I initially supplied a bitmap strip 128x16 and told the TreeView the images were 16x16. I've move the hotspot around in TreeView_BeginDrag ... For the most part, CreateDragImage is a black box - it just creates the draggable image. I've no idea how to affect the placement of the text relative to the image.
Any suggestions would be appreciated. Thanks in advance,
-Luther
|
|
|
|
|
I need to fill in numbers with all possible configurations of defined string length:
say choose string length N=5
and get all combinations from 00000 ... 99999
and so for any chosen N for the code to be universal
give some code please
9ine
|
|
|
|
|
9ine wrote: and get all combinations from 00000 ... 99999
Can you not just use a for /while loop?
"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 need to go to sleep...
yes I see looping thru 00000 ... 99999 is equal to scrolling thru all combinations
9ine
|
|
|
|
|
you have the maximum number for the combination like that :
long lMax = 0;
CString str = ;
for (int i = 1; i < str.GetLength(); i++) {
lMax += 9 * ::pow(10, i);
}
then, you iterator from 0 to lMax...
|
|
|
|
|
Sorry sorry I have awaken and realized ...
I need to code the parsing of:
given the number of dimensions N
say N=6
and given the maximum number of single dimension size
say a,b,c,d,e,f a=300,b=100,c=400,....
to parse thru all possible combinations of them
from 0,0,0,0,0,0
1,0,0,0,0,0
2,0,0,0,0,0
...
...
a,b,c,d,e,f
the total number of combinations will be a*b*c*d*e*f
9ine
|
|
|
|
|
if anyone can suggest better code?
m_dsize[] = {a,b,c,d, .... }
pos[] = {0,0,0,0, ... }
//pos will be filled with all possible configurations
while(true)
{
//increment counter
for(int i=0; i<dim; i++)
="" {
="" pos[i]++;=""
="" if(pos[i]="">=m_dsize[i])
pos[i]=0.0f;
else
break;
}
float sum=0.0f;
for(int i=0; i
|
|
|
|
|
9ine wrote: if(!sum) break;
Why are you using a logical NOT operator with a float ?
"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 thought it was not forbidden. why not float value stored as 32 bit number and if it is 0.0 then its 32 bit equivalent 0x00000000
9ine
|
|
|
|
|
9ine wrote: I thought it was not forbidden.
Just because something is syntactically correct does not also mean it is good practice.
9ine wrote: why not float value stored as 32 bit number and if it is 0.0...
Using the equality operator with float (or double ) is a really bad idea.
"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
|
|
|
|
|
Hi,
Does anyone know how I can remove the highlight selection in the listview control. I just want to be able to have the user to select the checkboxes.
Thanks.
|
|
|
|
|
Use the SetItem() method to turn off the LVIS_SELECTED state.
"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
|
|
|
|
|
You can use the following method to modify the state
for removing of selection where
state = 0
nMask = LVS_SELECTED
SetItemState( int nItem, UINT nState, UINT nMask );
Knock out "T" from CAN'T
You 'CAN' if you think you 'CAN'
-- modified at 0:36 Wednesday 5th April, 2006
|
|
|
|
|
Hi,
I've done a dialogbased project and created databases(MSACCESS) using recordset(class wizard).Now my problem is where do u declare this m_pSet?
In SDI u do it in VIEW Class,but in dialogbased where do u do it?
I get the foll errors when I execute the program:
m_pSet :Undeclared identifier
pls help me
swapna_signsin
|
|
|
|