Jay,
Cant have a trigger execute a function in a remote vb.net app.
Install the application on you DATABASE SERVER- make it a local APP... If
the messages are that important ... this will give you the quickest result!
A function CAN call a local exe ... I do it all the time - for broadcasting
status changes and sending critical alerts in an Patient Tracking system for
a hospital emergancy department...works like a hot dam ... even sends
messages to peoples pagers! If you DBA screams and yells and jumps up and
down - this is a database server, we are not install you little program on
it ... find out the persons name at the bottom of the DBA's paycheck, go to
them, tell them what is going on ... tell them what you are doing ... tell
them how critical this application / process is to organization - MISSION
CRITICAL ... tell them how much this program will impact the overall
performance of the database server ... sell it to them - the persons whos
name is at the bottom of the paycheck!
Again, if this is so mission critical, you must capture it at the moment the
data is made available...and you need fall-over, redundancy in you messaging
application.
what happens ... message in table ... 3 more seconds til the messaging
thread is fired ... 2 ... 1 ... oops, messaging machine is off-line! No
message sent! Now what? If on the database server ... if the data is saved,
the message is sent ... and if it is not sent ... alerts are sent... there
is a fail proof plan in place when messages are not SENT simply because the
system knows a message was suppose to be sent! However, if you are sending
messages for a machine that is off line and not polling for new messages
(because some network guy re-started the box and for got to restart your
process) ... there is now way of detecting unsent messages.
----------------------------------------------
What I do not understand ... is your reason to use '4' threads??? I know
speed ... mission critical . But why 4 threads??? Why not have a thread
for EACH MESSAGE ... 16 messages .... 16 threads! Using your reasoning,
would this not be even quicker!
----------------------------------------------
What I am saying is ... and have said before ...and is being repeated by
Chris ... he has taken my suggestion one step further by giving you useable
code... is you approach to multi threading the entire process is flawed ...
I am not argueing the need for multithreading in the process ... I am just
disagreeing with the need to multithread the entire process!
Example ... in plain text ... you figure out the code ...
1. Scenerio: Retrieve list of messages from the database... MessageBroker
.... have MessageBroker create a seperate thread for each message it has to
send!
So, proces is...
- Get list of message from database ...
- Loop through list ...
- for each record ... call a SendMessage method ... include all the
necessary information (parameters) for selecting or sending the message
- Have the SendMessage start a new thread ... send the message information
to this new thread ... so its know which message to send ... have this new
thread send the message.
- while this thread is processing (sending the message) ... return to your
list of messages in the messagebroker ...
- messagebroker gets next message ... messagebroker calls sendmessage ...
sendmessage creates a new thread ... sendmessage send message in new thread,
while program returns to the loop ...
Do you see what I am doing here ... the prgram will create a seperate thread
for EACH message. The messagebroker is your control, it will ensure you do
not send duplicate messages...
This will only work, if you have a single machine designated as your
MessageBroker!
2. Scenerio - Use your 4 threads ...
x = 1 to 4
- Thread x retrieves a message from the database ...
- Thread x prepares message to send ... before it sends ... it checks the
database ... to see if any other thread has sent the message ...
YES another thread has sent it ... Thread x , drops message, and gets
another message ...
NO, nobody has sent, thread x locks the message row in the database
(transactions and isololation levels ... have you looked at these yet),
updates the sending flagging ... sends the message ... updates the sent
flag...
- Thread x gets another message ...
This process ... will create a lot of wasted CHECKING and UPDATING and
DATABASE LOCKING to ensure messages are not duplicated between recipients.
This is not faster!
By having 4 threads working independant of each other, you are slowing down
the process! and adding 'more threads', you could be compound the issue!
You need some mechanism for communicating between your threads ...
- an exe ... the messagebroker approach ... telling the thread which message
to send.
- the database ... implement row level locking ... look at Isolation and
Transactions ... to ensure each message row in only processed by 1 thread...
- hard code it ... implement a design structure - add the ThreadToProcess
field - in to your solution. This will cause maintenance and scalability
issues later in life! And is poor design...and a poor work-around!
So, Jay, I have tried to shine some light on the problem for you, it is up
to you to decide your next steps ... if this is so mission critical, and you
are having these difficults, maybe consultant out for a solution
Jeff.