What I need is a timer mechanism that I can have running on an indicator on multiple charts concurrently... and am wondering if I should instead use the multi-threaded System.Timer.
This arises when I want to send two emails on a closing condition (in realtime) on the chart... One email to my email address... and a second to an SMS provider.
What I need to avoid is multiple instances of this thing trying to send emails concurrently, (or even 1 immediately after the other as in the code below), as I get an error logged saying there are too many connections from my host (that would be SMTP connections I presume)
I have this code:
SendMail([COLOR=#d69d85]my_email_address[/COLOR], [COLOR=#569cd6]string[/COLOR][COLOR=#b4b4b4].[/COLOR]Format([COLOR=#d69d85]"PD Alert: {0} BTC {1} @ {2}"[/COLOR], exit_bar_str, MI[COLOR=#b4b4b4].[/COLOR]Name, MI[COLOR=#b4b4b4].[/COLOR]FormatPrice(trade_price)), [COLOR=#569cd6]string[/COLOR][COLOR=#b4b4b4].[/COLOR]Format([COLOR=#d69d85]"{0} BTC {1} @ {2}"[/COLOR], exit_bar_str, MI[COLOR=#b4b4b4].[/COLOR]Name, MI[COLOR=#b4b4b4].[/COLOR]FormatPrice(trade_price)));
SendMail(sms_address, [COLOR=#569cd6]string[/COLOR][COLOR=#b4b4b4].[/COLOR]Format([COLOR=#d69d85]"PD Alert: {0} BTC {1} @ {2}"[/COLOR], exit_bar_str, MI[COLOR=#b4b4b4].[/COLOR]Name, MI[COLOR=#b4b4b4].[/COLOR]FormatPrice(trade_price)), [COLOR=#569cd6]string[/COLOR][COLOR=#b4b4b4].[/COLOR]Format([COLOR=#d69d85]"{0} BTC {1} @ {2}"[/COLOR], exit_bar_str, MI[COLOR=#b4b4b4].[/COLOR]Name, MI[COLOR=#b4b4b4].[/COLOR]FormatPrice(trade_price)));
So... maybe code like this might work?
Wait_Random_Seconds();
SendMail([COLOR=#d69d85]my_email_address[/COLOR], [COLOR=#569cd6]string[/COLOR][COLOR=#b4b4b4].[/COLOR]Format([COLOR=#d69d85]"PD Alert: {0} BTC {1} @ {2}"[/COLOR], exit_bar_str, MI[COLOR=#b4b4b4].[/COLOR]Name, MI[COLOR=#b4b4b4].[/COLOR]FormatPrice(trade_price)), [COLOR=#569cd6]string[/COLOR][COLOR=#b4b4b4].[/COLOR]Format([COLOR=#d69d85]"{0} BTC {1} @ {2}"[/COLOR], exit_bar_str, MI[COLOR=#b4b4b4].[/COLOR]Name, MI[COLOR=#b4b4b4].[/COLOR]FormatPrice(trade_price)));
Wait_Random_Seconds();
SendMail(sms_address, [COLOR=#569cd6]string[/COLOR][COLOR=#b4b4b4].[/COLOR]Format([COLOR=#d69d85]"PD Alert: {0} BTC {1} @ {2}"[/COLOR], exit_bar_str, MI[COLOR=#b4b4b4].[/COLOR]Name, MI[COLOR=#b4b4b4].[/COLOR]FormatPrice(trade_price)), [COLOR=#569cd6]string[/COLOR][COLOR=#b4b4b4].[/COLOR]Format([COLOR=#d69d85]"{0} BTC {1} @ {2}"[/COLOR], exit_bar_str, MI[COLOR=#b4b4b4].[/COLOR]Name, MI[COLOR=#b4b4b4].[/COLOR]FormatPrice(trade_price)));
So... two questions:
- Should I use System.Timer that is good for multiple threads... I think the answer is Yes, given different symbols' charts run in different threads, right?
- Is there a better way to achieve this?
T.

Comment