|
The best approach would be to have your worker thread sitting at a WaitForSingleObject() with the object being a CEvent or some such. Whenever data was available it would signal the event and the thread would grab the data. The thread function could set a flag to let the GUI know that new data was available. The GUI could check this in OnIdle, however you shouldn't do any lengthing processing there. It could just PostMessage() to the MainFrm telling it to do whataver.
Neville Franks, Author of ED for Windows. www.getsoft.com
|
|
|
|
|
I think I understand what you are asking for, so I'll take a shot at it.
First off, let me ask. Can you use IO Completion ports? If you only have to run on NT,2K+ and what data you are waiting for is socket related this might be the best solution for you. You would basically guarantee that your worker thread only runs when there is data regardless of if it is less than or greater than 20ms.
If that's not an option. You could use 2 worker threads to achieve what you are asking for. The first thread would be a higer prirotity thread using WaitForXXXObject with a set maximum time. It would execute your worker code every XX MS. (Note: as stated before, Windows doesn't guarantee a high level of precision in timing functions.) The second worker thread would be the lowest possible prirotity and would do the same thing the first thread does, except it would use Sleep(0) instead of WaitForXXXObject to release its timeslice before calling your worker code. Obviously, your worker code (not the thread which calls it, the actual code block) might need to be protected against multi-thread access using a CRITICAL_SECTION or whatever.
Just my 2 cents.
Matt Gullett
|
|
|
|
|
I understand what everyone is thinking. Well, Win OS is good enough for my purposes. Why I believe I need a high priority thread first is that I need to call a fucntion to acquire data from a card every so ...
For the most part, I have tried a little of what I thought up an dit works BUT it only reacts when a timer is called to read from the buffer that the high priority thread puts data to. The High priority thread has a sleep call at the moment.
The comment by Matt about the second thread doing a sleep to release timeslices confuses me a bit. What I am getting from it is that the worker high priority thread will be run whenever. Then when the lower priority thread is called (because nothing else happening) it will sleep and call the worker thread func. If there was no this lower priority thread, wouldn't it still work the same way?
In another comment, it was mentioned taht I coul dsend a message from my OnIdle func to my Main program to do the task of reading from the buffer. This sounds good. But I was wondering if it would then end up sending TOO many messages because I thought OnIdle is called often.
Thanks for the comments. Does anyone have any other comments on what I said above? I am really trying to figure out a way to do thing better!
|
|
|
|
|
Grr Ive just about had enough of Visual B*$£%y studio. Okay heres my problem ive written a program that runs buetifully in Debug and i mean buetifully not a single error when runnign it 100's of times etc.
Soon as i switch to release i get it just crashing or errors popping up saying some function failed. Okay one of teh biggest ones is CryptAcquireContext() fails with invalid parameter well hwo the hell can that be when the parameter is valid in debug. All i can think of is something is screwing up the memory where this is loaded has anyone got any ideas.
Peter
P.S Surely if something was screwing this memory area up it would be picked up in debud as an Assert failure?
|
|
|
|
|
Peter Liddle wrote:
well hwo the hell can that be when the parameter is valid in debug.
Two words: uninitialized variables
Check out John Newcomer's article here at CP about debug vs. release problems.
--Mike--
Buy me stuff! (Link fixed now)
Like the Google toolbar? Then check out UltraBar, with more features & customizable search engines!
My really out-of-date homepage
Big fan of Alyson Hannigan and Jamie Salé.
Sonork - 100.10414 AcidHelm
|
|
|
|
|
set your compiler's warning level to 4. this will catch a lot of stuff. (project / settings / C/C++ )
-c
There ain't no second chance
Against the thing with the forty eyes
|
|
|
|
|
you must also call "ZeroMemory" when passing some structs to API,if you do not call this the struct may have invalid data.
Casa.Sapo.pt
|
|
|
|
|
Thats what i thought that it would be unintalised variables but i have checked loads of times and can't find any and no warnign about them are bought up.
Maximaiano whats that about zeromemory i have zeroed all my structs when i initalise them shoudl i be zeroing them somewhere else as well?
Peter
|
|
|
|
|
look at this sample...
in this sample i am changing the text of one header item (CHeaderCtrl)
HDITEM hdi;
ZeroMemory(&hdi, sizeof(hdi)); //if i do not call this it will crash in release (most of the times)
hdi.mask = HDI_TEXT | HDI_FORMAT;
hdi.fmt = HDF_STRING | HDF_CENTER;
hdi.pszText = "Cool String";
m_Header.SetItem(i,&hdi);
why does it crash?
when we call SetItem we are passing all the items in the struct (hdi) not only the ones that we use (hdi.mask,hdi.fmt,hdi.pszText) and because the
the items that we didnt use may have invalid data the control crashes
the zeromemory "cleans" the struct , providing a safe way of sending a struct to a control without invalid data.
Casa.Sapo.pt
|
|
|
|
|
|
|
hello!
In my MDI app, I added a handler for the OnClose message in CDocument, so I can detect if the document has changed and promt for saving; the prompt has a Cancel button that prevents the document from being closed if the user changes his/her mind
My problem is that when the app is closed and a document has not been saved and you press the cancel button the program (obviously) crashes.
So what I want to do is call the OnClose method of all open documents before closing the main window and if one remains open prevent the app from closing. Can someone help me do this? I don't know how to reach the open documents' list from the main window.
thanks a lot!
marcela bovio
|
|
|
|
|
should have done a better search in the forum before asking
http://www.codeproject.com/script/comments/forums.asp?msg=34506&forumid=1647&kw=open+documents#xx34506xx
in case anybody else is interested
marcela bovio
|
|
|
|
|
hi all,
i have a dialog based class name called smp and global function which is callback compare function for sorting ctreectrl::CSortChildrenCB();
how can i try to access member variable of smp from compare function?
i had tried by declaring as followed inside the global function:
smp *tempsmp = new smp();
AfxMessageBox(tempsmp->strName);
i got empty string...
global in vc++ is very confusing..
|
|
|
|
|
you can not just create another smp... (it will instantiate a new smp object that does not have the correct strName)
you have to pass the pointer of you smp into the global function in order to access the strName
something like this:
void compare(smp* s)
{
AfxMessageBox(s->strName);
}
Casa.Sapo.pt
|
|
|
|
|
I see. and thank you
i solved my problem by creating new global variable which is to be able to access from global function.
after i set my new global variable = smp local variable , the problem solved.
|
|
|
|
|
try to use as few global fuctions and variable as you can...
Casa.Sapo.pt
|
|
|
|
|
Hi there ( It’s my last time ),
How can I load a JPEG file by Microsoft Forms Image 2.0 ActiveX, programically ?
There is a function:
SetPicture(LPDISPATCH newValue);
How can I pass value to first parameter of this function ?
Plz help me !
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
Hi there again,
How can I load JPEG files without using a ActiveX in my GDI programs ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
I'm sure you can find it in the articles of CP in GDI section.
Mazy
"The path you tread is narrow and the drop is shear and very high,
The ravens all are watching from a vantage point near by,
Apprehension creeping like a choo-train uo your spine,
Will the tightrope reach the end;will the final cuplet rhyme?"Cymbaline-Pink Floyd
|
|
|
|
|
Hi there,
Is Microsoft Forms Image 2.0 ActiveX in all of Windows versions ?
My month article: Game programming by DirectX by Lan Mader.
Please visit in: www.geocities.com/hadi_rezaie/index.html
Hadi Rezaie
|
|
|
|
|
I want to study proxy severs.
Please tell me where could find the Proxy Source code??
Davidwu
|
|
|
|
|
?????No body know?
|
|
|
|
|
Hi!
I want to disable some menu items in my IDR_MAINFRAME menu, when I hit a Button. I have a SDI-programm with a tab control. can somebody say my what to do?
thx Michi
|
|
|
|
|
You need to set a status indicator when you hit the button. Then, you need to handle the UPDATE_COMMAND_UI message.
for example:
void CSomeClass::OnButtonClick()
{
m_bEnableMenuItem = false;
}
void CSomeClass::OnUpdateUI(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bEnableMenuItem);
}
|
|
|
|