Hi MrKim, DouglasNYoung, mc73,
Thanks so much for your advice and sorry for my late response.
Personally, I think I would set a flag each time you access the database for writing and deleting and have the other Routines wait until the flag is free. Also, while I haven't tested this, make sure you close your cursors after reading data. It is possible they hold a lock on the records but I am not sure.
Yes I also think about it but finally I give up as if I create the flags, then there should be many of them as I have many Subs... Pls see below.
(Yes I do close the cursor each time)
You could put all your database read/writes in Try/Catch structures -and perform some loop until successful. But put a counter in the loop, and a maximum value, to ensure you don't end up in an infinite loop.
Douglas
That is a good solution. So far I can think only about this direction...
If you just insert the new message and then get it to your activity, I can hardly understand why you get this type of error, and especially the hang event. How are you refreshing your activity?
Well, I wish I can post the whole project here for your reference. But unfortunately it is a big project and it's my company project so I can just detail here my answer: From my previous post, I did not mention clearly, but actually when a message arrives, you should do many tasks, not just a simple INSERT task to the database. For example (pseudocode):
1) Load messages to user's chat interface
Cursor1 = SQL2.ExecQuery("SELECT * FROM Messages WHERE address=+112212345 ORDER BY datetime ASC")
2) User can send out a message during his chat at any time, so you have to be able to record new sent message and then refresh the Activity to update it into the chat thread
"INSERT INTO Messages VALUES(?,?,?,?)", Array As Object(Address, Contents, DateTime.Now, id))
3) Update the notification (refresh the new messages quantity);
4) User can delete an existing message during the chat
SQL.ExecNonQuery("DELETE FROM Messages WHERE address=?",Array As Object(phonenumber))
4) A new message arrives during the chat
"INSERT INTO Messages VALUES(?,?,?,?)", Array As Object(Address, Contents, DateTime.Now, id))
5) Access to database to check if new message is a "black list" one or not; if not, so allow it to pop up to the user, if yes, will have to block it and record into a block database;
5) Update the notifications;
6) Update the new message to user interface;...
The above is only simplified task list that I have to do, in the reality I have more than that (for example, user can add his chatting partner to blacklist, he can restore the existing message to inbox, he can receive other people's new SMS etc...)
So using flags is a little bit confusing as I will need many flags.