objective c - NSRunAlertPanel caused performance issue on multithreading -


occasionally have popup alert window in cocoa code segments. used nsalert directly have runmodal go while found nsrunalertpanel more easier achieve goal. decided switch alert functions nsrunalertpanel. seemed okay @ time。

now i'm adding multithreading. found nsrunalertpanel appears slower nsalert when calling in main thread.

code segments:

firstly create thread:

[nsthread detachnewthreadselector: @selector(tryrunloop:) totarget:self withobject:nil]; 

then functiontryrunloop in thread call alert window function in main thread:

while(1) [self performselectoronmainthread:@selector(showalert:) withobject:anobject waituntildone:yes];  

the function showalert in main thread rest things:

nsrunalertpanel(@"warning:",@"just testing", @"yes", nil, nil); 

as time goes response of popup window appears slower , slower.if use nsalert instead of nsrunalertpanel, or did not run popup method in main thread, symptom should disappear.

i found cpu usage different between these 2 methods. nsalert costs low cpu usage while hitting button time.

is able explain these phenomenons?

ps: not allowed put whole original project online i've created simple cocoa project in github simulate symptom , url ,please take @ known issues in readme file @ first.

alright, short answer don't use nsrunalertpanel. family of functions have been discouraged time now, , superseded nsalert. use nsalert instead.

(unfortunately class reference nsrunalertpanel etc. doesn't mention this; i'm trying remember first documented; perhaps release note)


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -