Is SMSInterceptor synchronous once a message is received?

markbarrett_1

Member
Licensed User
Longtime User
Hi,

I'm currently writing an SMS rebroadcast program (receive a SMS and rebroadcast it via an internet SMS service provider - much cheaper than the phone company) and I may spend some time in an SMSInterceptor MessageReceived event. What happens if a second SMS message is received whilst I'm processing the first message in the MessageReceived event? Does the message get queued and then the MessageReceived event is fired once the first message has been processed (aka MessageReceived completes and then gets re-fired to run a second time)?

The reason why I'm asking is do I need to do special things to make my code re-entrant?

Thanks.

Cheers.

M
 

agraham

Expert
Licensed User
Longtime User
The reason why I'm asking is do I need to do special things to make my code re-entrant?
No unless you do something that causes execution to return to the message loop. The only thing likely to do this is DoEvents.

Basic4ppc events raised from external sources running on a different thread rely on Form.Invoke to cross to the main application thread and in turn Invoke relies on placing messages on the application message queue. Most Basic4ppc control events are raised by the OS and also arrive by the message loop although library events raised by library code running on the main thread actually call their event Sub directly.

All Basic4ppc events are run on the main, usually only thread, even when called from another thread belonging to another process. This is so they can safely manipulate GUI elements. If a different thread fired the event, causing Invoke to be invoked, it is stalled until the event code returns so the queuing behaviour, if any, is determined by the code that fires the event and is not determined by Basi4ppc. No other event is accepted by Basic4ppc until any existing event returns unless code returns to the message loop when another event Sub may be invoked effectively interrupting the previous event and possibly causing reentrancy problems.

I hope this isn't too complicated - if it seems so it is because there is a lot happening behind .NET events.
 

markbarrett_1

Member
Licensed User
Longtime User
No other event is accepted by Basic4ppc until any existing event returns unless code returns to the message loop
Hi,

Thanks for the response. Yes I understand .net is complicated under the covers, but I only have a very superficial understanding hence asking the question.

So in my sms processing loop I go off and do a https: post request with the following commands. As I understand it these calls are synchronous and they shouldn't return to the message queue

WebResponse.New1
WebRequest.New1(URL)
WebRequest.TimeOut = 60000
WebResponse.Value = WebRequest.GetResponse
WebResponse.Close

BTW is there a simple way to trap when a http request fails (I've had to wind out the timeout value to cater for delays in internet dialing from the phone etc). At the moment if the webrequest timer pops the program dies with an error message (I need the code to be very robust so there mustbe someway of trapping a http failure).

Thanks.

Cheers.

M
 

markbarrett_1

Member
Licensed User
Longtime User
Hi,

Thanks Erel.

Hmmm. The joys of writing code communications code. Most of the work is done in error checking - the actual code that does the work is usually pretty simple.

Sounds like I will need to do something or risk program failure (I'm a network engineer by trade, firefighting is my volunteer night job :)). I can tell you a million things that can go wrong with your communication on the wire.

Agraham I've been looking at your thread library. If I create a thread (thread 1) from main and within that procedure create an object (say http request/response objects) and then I create a second thread (thread 2) from main with the same procedure with creates an object (say http request/response objects) will the http objects in threads 1 and threads 2 be distinct different objects. If so that is way cool and as long as you observe the locking rules to put stuff back into global variables then basic4ppc with your library is extremely powerful.

Thanks for your help always guys...It is appreciated. :)

Cheers.

M
 

agraham

Expert
Licensed User
Longtime User
will the http objects in threads 1 and threads 2 be distinct different objects.
Depending upon exactly what you mean by "create" (AddObject or New) the answer is yes, as long as they have different names. An object name includes the module to which it belongs so the same name can be used in different modules and still be distinct.
 

markbarrett_1

Member
Licensed User
Longtime User
Hi,

Hmm...Sounds like I need to create a thread pool using control keyword. Ok not a problem.

What about things like local variables? Just say I have 3 threads each running the same procudure, but each thread has different inputs, do I need to worry about local variables (aka with each thread instance does it create its own local variables)?

Thanks again.

Cheers.

M
 

markbarrett_1

Member
Licensed User
Longtime User
Hi,

Thanks again.

To round this thread out if you use an errorlabel that will trap a http timeout on a synchronous call and continue with program execution at the errorlabel and you can clean after the failed http request.

From my perspective if you don't get a response back to a http request, there is no way of telling what went wrong from an application perspective. The only thing you can tell is you didn't get a response. If you find yourself in that situation you have to decide whether you are going to retry the http request and how many times, delay between retries etc.

Appreciate your help as always. :)

Cheers.

M
 
Top