Click here to Skip to main content
14,691,952 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
actully i did windows service. only i test when start methord is executed then one file created and writing some text and also for stop methord another methord is creatcued and same. this code perfectly executed.but when i write some bulk of code instead of small code it is not executing .becoz the interval time is low.but when i increase the time interval then it is not install to my computer it show error "after install start methord is not excute" so please comment how to write bulk of code in window service please please...

my time interval is 1000

it is perfectly working in this code

string sfilepath = @"filepath/sample.txt";
string sdatetime = DateTime.Now.ToString();
System.IO.StreamWriter ofilewriter = new System.IO.StreamWriter(sfilepath, true);
ofilewriter.WriteLine("\n" + "Start Excuting");
ofilewriter.Close();


////when i put this code
con.Open();
string str = "select filed from tablename where field= 1 and field= 0";
MySqlCommand cmd = new MySqlCommand(str, con);
MySqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
mailaddress = sdr["field"].ToString();
destinationpath = sdr["field"].ToString();
extnid = sdr["field"].ToString();

string path = destinationpath.Replace('@', '\\');
MailMessage mail = new MailMessage();

SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");

mail.From = new MailAddress("source mail address");
mail.To.Add(destination mail address);
mail.Subject = "Configuration File";
mail.Body = "Report";
Attachment attachment = new Attachment(path);
mail.Attachments.Add(attachment);
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential("source mail", "passwo0rd");
SmtpServer.EnableSsl = true;

SmtpServer.Send(mail);
MessageBox.Show("message sent");

//update in table message was send.

}
con.Close();

}
it does not work properly,only message sent but no update in table and sometime message is not send like this.



thanks in advance....
Posted
Updated 19-Aug-15 21:12pm
v3
Comments
   
You are talking about nothing. No one can advise anything certain based on your information.
—SA
Sarath kumar.N 20-Aug-15 1:45am
   
At least post some code.
Sanket Saxena 20-Aug-15 1:53am
   
Actually there is no solution for your problem as we cant see the code, second thing there is nothing related to "bulk of code" as you have said. You can manage as many line of code in windows service.
Check your code. Do some Research and try o fix it. Else update your question with proper information.
Mayank Vashishtha 20-Aug-15 3:32am
   
Why don't you increase the time interval?

Please see my comment to the question: you are talking about nothing.

Sorry for not giving you a solution; this is probably impossible, based on your information. Only one thing is more or less clear: you created incorrect dependency on time interval, I have no idea why. It has nothing to do with "bulk of code". So, here is the hint which may lead you to something better: your "bulk of code" just manifests your rotten design, which is incorrect in all cases, even with little code; and only by chance (combination of time intervals) you have an illusion that it "works". Roughly speaking, should you use slower CPU, and your application with "small code" will stop working. In other words, you don't have working application at all.

For the most general idea, get familiar with the concept of race condition. I faced with more clear and definitive term meaning the same: "incorrect dependency on the time of execution": http://en.wikipedia.org/wiki/Race_condition[^].

It's likely that your case in more trivial. As you mentioned "interval time", I can assume you use some timer. Timers are potentially unreliable and should be used with great care, or not used at all. One simple idea is: imagine that your next timer event comes when the event handler invoked by previous timer even is not yet executed. It can create a great mess. So, the safe alternative would be using a separate thread working in a cycle, possibly with some sleep time in each cycle; in more advanced approach, you can adjust the sleep time based on real time measurement of time interval consumed by previous iteration. This is just one very basic idea. The "real" solution would need much more detailed knowledge or your problem.

—SA
   
Comments
Member 11849346 24-Aug-15 3:12am
   
i got solution of this problem by reasearch.actually this problem is dou to time interval is small so that it repeat again again when the time is elapsed.but whole code is executing in this time(ex 1000ms).so if increase the time interval then it is not installed and gives error service is not timely fashion. for this problem i wrote a code
this is as when timer object will start then service execute for ex- otimer.start();
it will going on again again when the time interval is finished. after otimer.start()
it will go to timer elapsed event in this event whole code is present.this event is execute when the timer is start() so in this event i stop manually to the timer ex-otimer.stop() after that whole code is written and after that again start the otimer ex-otimer.start .so whole code is written in between otimer.stop() and otimer.start() in this way a bulk of code will execute.
i got solution of this problem by reasearch.actually this problem is dou to time interval is small so that it repeat again again when the time is elapsed.but whole code is executing in this time(ex 1000ms).so if increase the time interval then it is not installed and gives error service is not timely fashion. for this problem i wrote a code
this is as when timer object will start then service execute for ex- otimer.start();
it will going on again again when the time interval is finished. after otimer.start()
it will go to timer elapsed event in this event whole code is present.this event is execute when the timer is start() so in this event i stop manually to the timer ex-otimer.stop() after that whole code is written and after that again start the otimer ex-otimer.start .so whole code is written in between otimer.stop() and otimer.start() in this way a bulk of code will execute.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900