|
Thanks.. I was reading throught this article and i came upon a small problem. It's the part where it teaches you how to shut down the thread: http://www.codeproject.com/threads/usingworkerthreads.asp#Shutting%20down%20a%20thread%20from%20a%20view%20or%20main%20frame
The problem is this function: ' WaitForSingleObject(myWorkerThread->m_hThread, INFINITE); '
This function will wait for the thread to terminate before proceeding. However, it seems like my thread doens't ever terminates although in actual fact it does. Why is this so? Am I missing an output signal saying that my thread is done? BTW, i used a very simple 'for' loop in my thread, Just like in the example. It looks something like this:
m_progress.SetRange(0,100);<br />
for(x = 0; running && x < m_num; x++)<br />
{<br />
count++;<br />
counter = (float) count/m_num;<br />
m_progress.SetPos((float)counter*100);<br />
}<br />
<br />
m_progress.SetPos(0);<br />
running = FALSE;
|
|
|
|
|
|
|
Thanks.. I managed to implement worker threads in my program but i noticed 1 problem. Whenever i call the UpdateData(FALSE) function in my thread, a 'Debug Assertion Failed!' error pops up. Is there a way to overcome this problem?
|
|
|
|
|
|
Well, i was using UpdateData(FALSE) to change some CStatic text in my Dialog Box using the worker thread but it always gives me that error. There is no compilation error. Just that error when i run the thread.
I have another question, how do i start another funcion upon the completion of my thread? Is there a way i can 'signal' to my other function saying that the worker thread is done?
|
|
|
|
|
(1)It seems that this problem isnt for thread do you have a specific code in your thread and
maybe this error is in declare thread (i know your code is ok this error is a runtime error)
----------------
(2)
Hope I understood your question
Do you need to GetExitCodeThread if its not you can check your thread when it created
|
|
|
|
|
Sorry but i don't quite get your explanation for my second question. What i want to do is to call another function when my thread finishes whatever it was doing. Hope you can explain it to me again. Thanks.
|
|
|
|
|
when you create a thread how do you finish it.TerminateThread if you use from this function then you can use GetExitCodeThread
that retrieves status from thread and you can check status returned that is STILL_ACTIVE or no
Is this your question?
|
|
|
|
|
Thanks for your help... i've tried it but i'm not sure if its right.
Does this look right to you:
TerminateThread(myWorkerThread,GetExitCodeThread(myWorkerThread,0));
Another Question:
Assuming the code below,
MyDialog::MyThread()<br />
{<br />
int i = 0;<br />
while (i < 5000)<br />
i++;<br />
}
I understand that a worker thread is not supposed to touch a GUI object. Is there a way to terminate this thread(when it completes, ie i = 5000) and call another function that can actually change some GUI variables?
Thank you so much for your help.
|
|
|
|
|
one thing that i think its important a thread remain in system until you terminate it and close all handle with CloseHandle
(1)TerminateThread is for finish a thread when you call this function for get exit value if thread is active you get STILL_ACTIVE else you get value that is in second parameter from this function dxExitCode
(2)
Hope I understood your question
It seems that its depend to previous your questions(check when i=5000 finish thread and load your function) is your question?
(you can use from WM_TIMER instead a while(5000) when you need to 5000 you can set SetTimer(...) and when i=5000 in wm_timer you can Kill timer with killTimer and run another function )
if its your answer i am glad if its not your answer so
you can ask and if i can i answer to you
|
|
|
|
|
Hi all,
Iam having a checksum algo implemented in my code.
The Pc receives a packet from microcontroller and then does this as a check:
for(i=0;i < max_length-1;i++)<br />
{<br />
checksum ^= recd_buf[i];<br />
}
then this checksum is compared with the last member fo the received packet which has the checksum sent from microcontroller.
if(checksum != recd_buf[max_length-1])<br />
{<br />
"bad packet"<br />
}
but i always get the values to be not equal. By printing out the received packet details, they are all correct.
there s no error on the microcontroller end.
There is error in the calcualtion of checksum at the Pc end (the code shown above).
Can anyone help? I know there are various checksum algos available. but i want to find out the bug/error in this.
thanks in advance.
-- modified at 0:39 Monday 14th August, 2006
|
|
|
|
|
look here
if(checksum != recd_buf[max_length-1])
{
"bad packet"
}
do you think in " recd_buf[max_length-1]) "
the "max_length-1 " is ok. why donot you compare with
"max_length " . Because in first "for loop " your iterator "i" starts from " 0 " but at this time you are just checking maximum length.
as long I think
if(checksum != recd_buf[max_length])
{
"bad packet"
}
Tanvon
the brain behind ...
|
|
|
|
|
I think his loop is correct, because you usually don't include the check sum value in the check sum algo, hence the < max_length - 1 in the loop control. If you did recd_buf[max_length], that would be out of bounds, since it's zero based.
Thinking about it more, maybe the checksum should be part of the algo, maybe try i < max_length, instead of max_length - 1, and see if that works.
I've seen some other algorithms as well, but try that first.
- S
50 cups of coffee and you know it's on!
|
|
|
|
|
Is checksum initialized properly?
What are your data types? When using the bitwise operators, all types should be unsigned. You may be getting bit by sign-extension or some other result of integral promotion.
--Mike--
Visual C++ MVP
LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ
|
|
|
|
|
Hi,
I initialise checksum to zero everytime before calculating it.
Also, the data types are of signed16 or short and few are of float values.
But the received buffer is declared as char type and all the values are stored as 8 bit values in recd_buf[0] to recd_buf[max_length-1].
from the microcontroller end, the checksum is calcualted in a similar way and the checksum value is stored in the last position ie., sent_buf[max_length-1].
and in the PC end, the checksum is calculated the same way,(as in my previous message),
and the calcualted checkum is compared with the value that was sent as the last member of the packet from microcontroller.
Does this info help you? Any ideas/ suggestions?
|
|
|
|
|
hey all,
Thanks all for ur help.
I could get my algo going.
1. I had the checksum declared as char-- but now changed it to unsigned char.
2. the next thing was:
I was comparing the checksum value with the last member of the received packet array (where the array was declared to be signed char)
I created a temporary unsigned char variable and copied the last member of the array (checksum from microcontroller) to it.
Then used this temporary variable for comparing with the checksum calculated in Pc.
It works perfect.
It was basically signed/unsigned datatype problem..
Thanks to all again for ur help.
|
|
|
|
|
Have you tried to have the message sent with length equal to max_length including the checksum?
if(the length of the message is not equal to max_length)
{
if(checksum generated to array[real_length-1])
wrong;
else // checksum generated to array[max_length-1]
{
wrong;
// before and after transmission, index from real_length to max_length-1 =
// unknown values
}
}
else
must be correct
|
|
|
|
|
Hello,
After switching to release mode, the ProcessShellCommand show me a messagebox that say "error to build a empty document" and the fonction return false. I do not understand because my application was running without any problem before and now I get this problem.
What can I try to solve my problem.
Thank you
AutreChien
|
|
|
|
|
Hi,
I tried pEdit->SetWindowText("/n"); but a junk character is displayed instead of going to new line .
Plz help.
thanx in advance
|
|
|
|
|
try "\r\n"
also make sure your edit control style is ES_MULTILINE
|
|
|
|
|
Yeah.
It worked.
Thanx once again.
|
|
|
|
|
See here[^] maybe it is some helpful to you
|
|
|
|
|
what functions does netshell.dll include?
what parameters do they have?
And, thanks.
|
|
|
|
|
DllCanUnloadNow
DllGetClassObject
DllRegisterServer
DllUnregisterServer
NcFreeNetconProperties
NcIsValidConnectionName
HrLaunchNetworkOptionalComponents
HrCreateDesktopIcon
HrLaunchConnection
HrRenameConnection
InvokeDunFile
DoInitialCleanup
NetSetupRequestWizardPages
NetSetupFinishInstall
NetSetupAddRasConnection
HrDetectLegacyNetCards
HrUninitLegacyNetCardDetection
HrOemUpgrade
HrGetAnswerFileParametersForNetCard
HrGetInstanceGuidOfPreNT5NetCardInstance
NetSetupSetProgressCallback
NetSetupInstallSoftware
Open netshell.dll with Dependency Software !
|
|
|
|