ios - Work with Sqlite and UI action in main queue -


i need help. write app, should save data , @ same time show they. has problem. both operations working in main queue. can do? thanks!

my ui code

dispatch_async(dispatch_get_main_queue(), ^{     [self.hostview.hostedgraph reloaddata]; }); 

my db code

-(bool)addnewmesurable:(mesurable*)mesurable{     if (!_database) [self createdatabase];     const char *chardbpath = [_dbpath utf8string];     if (sqlite3_open(chardbpath, &_database) == sqlite_ok) {         char* errormessage;         sqlite3_exec(_database, "begin transaction", null, null, &errormessage);          nsstring *query =         [nsstring stringwithformat:@"insert %@ (value , date, time)  values (? , ? , ? )",[sensor sensornametostring: mesurable.sensor]];         sqlite3_stmt *statement;          if (sqlite3_prepare_v2(_database, [query utf8string], -1, &statement, null) == sqlite_ok) {              sqlite3_bind_text(statement, 1, [[mesurable.value stringvalue] utf8string], -1, null);             sqlite3_bind_text(statement, 2, [[mesurable getstrinddate] utf8string], -1, null);             sqlite3_bind_text(statement, 3, [[mesurable getstrindtime] utf8string], -1, null);             //             if(sqlite3_step(statement) != sqlite_done){                 nslog(@"error add data sensor - %@ ", [sensor sensornametostring: mesurable.sensor ]);              }             else nslog(@"done");             sqlite3_clear_bindings(statement);             sqlite3_reset(statement);             sqlite3_exec(_database, "pragma synchronous = off", null, null, &errormessage);             sqlite3_exec(_database, "pragma journal_mode = memory", null, null, &errormessage);         }         sqlite3_exec(_database, "commit transaction", null, null, &errormessage);         sqlite3_finalize(statement);         sqlite3_close(_database);     }      return yes; } 

try this:

you can use dispatch_queue_priority_low,_high , _default :

dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_low, 0), ^{     // send result main thread can     // uikit stuff. u can update ur ui       dispatch_async(dispatch_get_main_queue(), ^{         // update db content     }); }); 

Comments

Popular posts from this blog

inversion of control - Autofac named registration constructor injection -

verilog - Systemverilog dynamic casting issues -

ios - Change Storyboard View using Seague -