You are correct of course but Benjamin has some "fundamentals" problems that he needs to get straight before any of that matters. See my last post, it's a common theme (struggling to grasp the concepts) that occurs with an introduction into both subjects, threading and asynchronous operations. Actually for me, anytime I have a gap in time of doing either, I go through the struggle each time I have to do it again.
it's a common theme (struggling to grasp the concepts) that occurs with an introduction into both subjects, threading and asynchronous operations.
Indeed
led mike wrote:
Actually for me, anytime I have a gap in time of doing either, I go through the struggle each time I have to do it again.
Heh it's like that for me with anything. That's probably the biggest reason I respond to questions here - so I can keep
a little sharp on stuff I don't use often. Graphics, asynchronous I/O, and threading, however, I do every day, all day.
I tried something like that but it would not work. I put the ReadFile in a while loop and I changed the offset of the buffer and the number of bytes to read by an amount I got from a call to GetOverlappedResult but it gave me weird results.
I guess led mike is right when he says that there is fundamental things I need to understand before getting things right.
Thanks for your comment and suggestion.
Benjamin Racette
CAE software developer
racette@cae.com
Does a call to GetOverlappedResult() keeps on reading or writing or should I call WriteFile or ReadFile again and again until its done?
You are responsible for checking the overlapped result and sending/receiving any remaining bytes.
FWIW, if you are calling GetOverlappedResult() right after a function call fails with ERROR_IO_PENDING,
then you're essentially doing synchronous I/O, and all you've done is added complexity to the code.
hey, that's nice to answer, but you know, we have dedicated forums, so if a question is asked at the wrong place, we shouldn't answer, because it will encourage others to ask anywhere.
I see you also answered the "Time" Question. Same remark applies there too.
actually, he was too much asking for somthing that looks like "please do my homework for me 'cause i didn't listen to the professor and now I don't know how to do that simple code"...
that's why, before giving him some working code, i prefered ask him first what he had already tried & written...
Have you extracted the date/time from the control using the DTM_GETSYSTEMTIME message or GetTime() method?
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
Hi,
I have created a 'please wait' dialog which is loaded when a user clicks on a button. A new thread is launched to load the button so the main thread can continue what it is doing.
The button code;
CPleaseWait *dlgWait = new CPleaseWait(this);<br />
AfxBeginThread(PleaseWaitThread, dlgWait);
It is very simple code, which I have had working before.
The problem is that when called, DoModal never returns, so the dialog doesnt get displayed (it doesnt get as far as InitDialog). The main thread continues running however.
If I place a 'return;' directly after the AfxBeginThread() then the dialog DOES display. If I place 'while(1) Sleep(100);' (or any other code) after the AfxBeginThread() then it does not return.
I have narrowed the problem down to a particular line (510) within 'dlgcore.cpp'
You're using a worker thread to create a user interface object?
Personally I dont see the need for a thread at all.
On Button Click:
Disable the main window.
Create and show a modeless please wait dialog.
Do work.
Destroy the modeless please wait dialog.
Enable the main window.
I think you are mixing the parent between threads, what about having the new CPleaseWait with (NULL) ??
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Your Thread Dialog wants to disable the main dialog.
There can be only one modal dialog per Thread. -> Parent = NULL or modeless Dialog (tip: with new and self destruction)
"Normal is getting dressed in clothes that you buy for work and driving through traffic in a car that you are still paying for, in order to get to the job you need to pay for the clothes and the car and the house you leave vacant all day so you can afford to live in it." - Ellen Goodman
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
Using "new CPleaseWait(NULL);" didn't fix the problem, oh, and I was using dlg->DoModal (as opposed to .DoModdal) it was a typo as the machine I am coding on isnt networked
I ended up using the modeless after disabling the main form, as suggested.
I have another question, not too important anymore, but would be handy to know. Inside the InitDialog() I had a new thread which alters the contents of a label to show the search hasnt crashed. It has worked before in the old application (I have just realised that the old problem didnt exist then as it was being used as a splash screen when the app was started, hence no parent). Now, the 'SetWindowText()' to update the label runs once, then doesnt return the second time. I cant look any further into it as no code is available for debugging (other than assembly) meaning it is quicker for me to delete that bit
Like i say, its not important now, but any ideas?
Thanks for the help everyone, I had been staring at those lines of code for hours!
I had problems with something similar in one project. I was using static labels to show variable datas. It worked good sometimes, but not as I wanted. So I changed them with Edits, set the protection to write and erase the border (all in resource editor), then just calling SetWindowText was enough and never failed.
BTW, are you erasing the background before sending the message to update screen?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson