|
Hi Tim,
I basically agree with you but I was left with the distinct impression that he wasn't really trying to handle errors, hence my reply. I mean if he is ok to let the thread crash then why not the app.
I run a number of worker threads in ED and untill now I never thought about the possibility of one crashing and having to be restarted. Mind you I put a loy of effort into trying to ensure everything is as robust as I can and then handling errors as best can be. This is an app that is used by a lot of people, but it certainly isn't mission critical.
I don't know where you picked up on the thread running in a foreign process space. That would indeed warrant a much more stringent implementation.
But as I said to start I basically agree with you.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
Infact I am running the thread in a foreign process space. So I don't have an option of monitoring the thread status and creating a new thread if there is a termination. Inspite of handling errors extensively, I am worried that an abnormal termination is possible.
Neville, I did a bit of reading on win32 thread implementation and I do agree that the idea of a thread restarting itself doesn't make sense May be I have to rely on effective error handling
Thanks,
Aralguppe.
|
|
|
|
|
Hi Aralguppe,
I'm not saying it doesn't make sense to restart a thread, I'm just concerned about why it is stopping in the first place and would start by focusing my efforts on ensuring it keeps running whenever possible. If it has to be restared then it can PostMessage() back to the main thread to get it to create the thread from scratch.
If this is a file monitoring app why does the thread need to be in another process? Even if it is and this "other process" is your code then my comments still apply.
Neville Franks, Author of ED for Windows www.getsoft.com and coming soon: Surfulater www.surfulater.com
|
|
|
|
|
Like Neville said, the key is to ensure that your thread never exits in the first place. One simple way to do that is to encapsulate the body of the thread in a try/catch block:
UINT ThreadFunction(LPVOID parameter)
{
for ( ; ; ) {
try {
}
catch (...) {
}
}
return 0;
} The catch (...) block catches all exceptions. Putting the try/catch block inside the for( ; ; ) loop creates the 'automatic restart' effect you are looking for.
Note that the catch (...) is typically considered to be poor practice. Too many programmers use it rather than catching the exact exceptions that they are interested in, which means error handling stops at that spot. In your case it would be a valid usage, since the catch (...) occurs at the outer edge of the executable code for the thread.
Software Zen: delete this;
|
|
|
|
|
Gary, I have added try catch blocks with catch(...) like you have mentioned. But I have to take care of all possible scenarios even one where the thread is forcibly terminated! Probably am asking for too much
Thanks,
Aralguppe.
|
|
|
|
|
Aralguppe wrote:
even one where the thread is forcibly terminated
One way to do that is to write your program as a service. Services can be set to automatically restart in the event they are terminated, or they crash.
Software Zen: delete this;
|
|
|
|
|
Hi,
is there any rotate text function in MFC that I can call anywhere out site the onPaint. I found all examples that in order to rotate the text I have to do it in onPaint()
thanks in advance
|
|
|
|
|
Anywhere
OnMouseMove might make sense for you?
Why do you need to call it outside OnPaint()...that function is there to let you draw...
The word of the day is legs, let's go back to my house and spread the word
|
|
|
|
|
well,
I need to build a function with multi functionalities like this
SetFontF(fontPoint,FontName,bold,rotate,.)....like that so I can call in any other functions in my project. Do you think is it possible to do that? Sorry I am brandnew in MFC.
Thanks a lot for your replying.
|
|
|
|
|
anyone, please give me an idea please......................
|
|
|
|
|
Is there a way i could define my own keywords, so that they would be the same color as the other predefined keywords?
for example.
i have keywords set to be Green, and i have black background.
the uppercase versions of char, bool, void, etc. dont show up Green
while the lowecase ones do.
so is there a way i could define my own keywords so they would show up green?
|
|
|
|
|
Yes. Create a file called usertype.dat in the SharedIde/bin directory in which Visual Studio is installed. Put your keywords in that file, one per line.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
there is no SharedIde folder however,
could this be the right folder?
C:\Program Files\Microsoft Visual Studio\VC98\Bin
just a thought, i didnt speicify i have the Enterprise Edition, i dont think that would make a difference would it?
and what about other highlighting like operators? could i set some of those, i generally define and as && , or as || etc. in small programs no one else will see the source too
|
|
|
|
|
Try C:\Program Files\Microsoft Visual Studio\Common\IDE .
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin
this one worked
ok is there a way i could make different ones a different color
like i have
BOOL
VOID
and
or
and i set user types to green
is there a way i could set
and
or
to show up another color instead of green?
like something i could add to the right of the line like
and COLOR #FF00FF
or something like that?
|
|
|
|
|
Tools | Options | Format
Category = Source Windows
Colors = User defined keywords
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
that changes all of them to one color, i want to know if there is a way i could set them to be different colors
for example i defined
VOID
BOOL
and
or
as user types,
is there a way i could make "VOID" and "BOOL" be green while "and" and "or" will be a different color like red
|
|
|
|
|
Sorry, I replied in haste. Don't know how you'd go about doing that.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
1. When I create a windows program and don't have it in focus it seems to end proccessing. This is where I place my code:
<br />
while (GetMessage(&msg, NULL, 0, 0)) <br />
{<br />
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) <br />
{<br />
TranslateMessage(&msg);<br />
DispatchMessage(&msg);<br />
}<br />
}<br />
Is there anyway I can make sure that my program is being run all the time, even if it's not in focus?
2. My second question is about simulating the keyboard, I know about PostMessage(). However, with this function I must post
a key press to a certain window, what I want to do is to simulate a keypress to windows.
//Ylis
|
|
|
|
|
The hidden application will receive system messages but not the windows messages... Key press are windows messages and u will get it only if that window is in focus.
I am sure, i guesss for your problem you need to implement a keyboard hook.
"When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)
|
|
|
|
|
oki, thx
|
|
|
|
|
To simulate keyboard messages, I guess SendInput() would be a more appropriate option.
- Nirav
* Don't wish it was easier, wish you were better! *
|
|
|
|
|
Hello, I have a problem with IDirectSound8::SetCooperativeLevel.
The DirectX SDK tells that you have to call IDirectSound8::SetCooperativeLevel immediatly after creating a IDirectSound8 object.
the prototype of IDirectSound8::SetCooperativeLevel is:
HRESULT SetCooperativeLevel(
HWND hwnd,
DWORD dwLevel
);
My app framework doesn't have any window at the moment this function has to be called.
When I set hwnd to NULL, the function fails(E_INVALIDARG).
What should I use as hwnd here?
Thx
Don't try it, just do it!
|
|
|
|
|
That means you really need to create a window before you call that function... I have see few DirectX samples and every one of them created a window before it is called. So i think its a compulsary option.
"When death smiles at you, only thing you can do is smile back at it" - Russel Crowe (Gladiator)
|
|
|
|
|
Hi again, my application doesn't close anymore after the execution of:
if( FAILED( DirectSoundCreate8( NULL, &gpDSP, NULL ) ) )
return FALSE;
before returning from main procedure i call gpDSP->Release(); , but after returning from main proc the app loops somehow through kernel32, ntdll and the kernel.
what is wrong with this?
Don't try it, just do it!
|
|
|
|