By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,671 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,671 IT Pros & Developers. It's quick & easy.

How to disable automatic stop on window service?

P: n/a
Hi,

I'm developing window service application on C# 2005.
The service is to read a new excel file on certain directory, and
process it to database.
The service work find on XP.
But when I install the application on Windows Server 2003, when i
start the service it said:
"The <my serviceon Local Computer started and then stop. Some
service stop automatically if they have no work to do , for example ,
the Performance Logs and Alerts System."

So my service will never run.

On my service I'm using File System Watcher Component.

What should I do?

Thanks.
Jul 13 '08 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On Jul 13, 1:36*pm, Lemune <alfredosilito...@gmail.comwrote:
Hi,

I'm developing window service application on C# 2005.
The service is to read a new excel file on certain directory, and
process it to database.
The service work find on XP.
But when I install the application on Windows Server 2003, when i
start the service it said:
"The <my serviceon Local Computer started and then stop. Some
service stop automatically if they have no work to do , for example ,
the Performance Logs and Alerts System."

So my service will never run.

On my service I'm using File System Watcher Component.
It would help if you explain in more details how exactly you're using
that component (and, in general, how your service is written). Code
snippets would be even better.
Jul 13 '08 #2

P: n/a
Lemune wrote:
I'm developing window service application on C# 2005.
The service is to read a new excel file on certain directory, and
process it to database.
The service work find on XP.
But when I install the application on Windows Server 2003, when i
start the service it said:
"The <my serviceon Local Computer started and then stop. Some
service stop automatically if they have no work to do , for example ,
the Performance Logs and Alerts System."
This means your service crashed during startup, which could have any number
of causes. Consult the event log for more details, and hook up an event
handler to AppDomain.UnhandledException in your service that logs to a file.

--
J.
Jul 13 '08 #3

P: n/a
On Jul 13, 5:43*am, Jeroen Mostert <jmost...@xs4all.nlwrote:
Lemune wrote:
I'm developing window service application on C# 2005.
The service is to read a new excel file on certain directory, and
process it to database.
The service work find on XP.
But when I install the application on Windows Server 2003, when i
start the service it said:
"The <my serviceon Local Computer started and then stop. Some
service stop automatically if they have no work to do , for example ,
the Performance Logs and Alerts System."

This means your service crashed during startup, which could have any number
of causes. Consult the event log for more details, and hook up an event
handler to AppDomain.UnhandledException in your service that logs to a file.

--
J.
I can't remember for certain, but it sounds more like the service
stopped by choice. When a service crashes or throws an exception you
get a message stating that the service failed to start altogether.
Jul 13 '08 #4

P: n/a
Brian Gideon wrote:
On Jul 13, 5:43 am, Jeroen Mostert <jmost...@xs4all.nlwrote:
>Lemune wrote:
>>I'm developing window service application on C# 2005.
The service is to read a new excel file on certain directory, and
process it to database.
The service work find on XP.
But when I install the application on Windows Server 2003, when i
start the service it said:
"The <my serviceon Local Computer started and then stop. Some
service stop automatically if they have no work to do , for example ,
the Performance Logs and Alerts System."
This means your service crashed during startup, which could have any number
of causes. Consult the event log for more details, and hook up an event
handler to AppDomain.UnhandledException in your service that logs to a file.

I can't remember for certain, but it sounds more like the service
stopped by choice. When a service crashes or throws an exception you
get a message stating that the service failed to start altogether.
Not on Windows XP, at least; I tested it. If the service throws an exception
in its OnStart(), you'll get the exact message the OP described. The event
log will contain the exception details.

A .NET service can't really stop by choice, except through calling
Environment.Exit() (or by explicitly connecting to the SCM and stopping
itself, but that's just backwards).

--
J.
Jul 13 '08 #5

P: n/a
Thanks all for your quict reply

this is my snipped code ( I just translate it because i use my on
language)
Expand|Select|Wrap|Line Numbers
  1. public partial class HCCPReader : ServiceBase
  2. {
  3. DateTime _lastFileTime = DateTime.MinValue;
  4. protected DateTime _lastFTPTime = DateTime.MinValue;
  5. protected DateTime _lastUploadTime = DateTime.MinValue;
  6. protected DateTime _lastBankUploadTime = DateTime.MinValue;
  7.  
  8. System.Timers.Timer _newTimer = new System.Timers.Timer();
  9.  
  10. public HCCPReader()
  11. {
  12. InitializeComponent();
  13. }
  14.  
  15. protected override void OnStart(string[] args)
  16. {
  17. // TODO: Add code here to start your service.
  18. _lastFileTime = DateTime.MinValue;
  19. fswUpload.Path = Common.GetUploadSettlementPath();
  20. fswUpload.EnableRaisingEvents = true;
  21. fswFtp.Path = Common.GetFTPPath();
  22. fswFtp.EnableRaisingEvents = true;
  23. fswBankNotify.Path = Common.GetUploadBankPath();
  24. fswBankNotify.EnableRaisingEvents=true;
  25. _newTimer.Interval =3600000;
  26. _newTimer.Elapsed += new
  27. System.Timers.ElapsedEventHandler(ServiceTimer_Tick);
  28. }
  29.  
  30. protected override void OnStop()
  31. {
  32. // TODO: Add code here to perform any tear-down necessary to stop
  33. your service.
  34. fswUpload.EnableRaisingEvents = false;
  35. fswFtp.EnableRaisingEvents = false;
  36. fswBankNotify.EnableRaisingEvents = false;
  37. }
  38.  
  39. private void ServiceTimer_Tick(object sender,
  40. System.Timers.ElapsedEventArgs e)
  41. {
  42. SunFile.Clear();
  43. Clear.ClearDirectory();
  44. }
  45. private void fswFtp_Changed(object sender,
  46. System.IO.FileSystemEventArgs e)
  47. {
  48. DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
  49. DataTable _dataExcel = new DataTable();
  50. try
  51. {
  52. if (_fswFileTime _lastFTPTime)
  53. {
  54. _lastFTPTime = _fswFileTime;
  55. bool _isFileComplete = Common.IsFileCompete(e.FullPath);
  56. int _tries = 0;
  57. while (!_isFileComplete && _tries < 15)
  58. {
  59. System.Threading.Thread.Sleep(1000);
  60. _tries++;
  61. _isFileComplete = Common.IsFileCompete(e.FullPath);
  62. }
  63. if (_isFileComplete)
  64. {
  65. //here sistem to read excel file
  66. _dataExcel = Reading.GetDataExcel(e.FullPath);
  67. //column 10
  68. string[] _arrayFileName = e.Name.Split('_');
  69. Decimal _fileTotal = 0;
  70. Decimal _totalAmount = 0;
  71. try
  72. {
  73. _fileTotal = Convert.ToDecimal(_arrayFileName[3]);
  74. }
  75. catch
  76. {
  77. _fileTotal = -1;
  78. TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
  79. with file name template.");
  80. }
  81. if (_fileTotal != -1)
  82. {
  83. foreach (DataRow _record in _dataExcel.Rows)
  84. {
  85. if (_record[0].ToString() == "S" || _record[0].ToString() == "Z" ||
  86. _record[0].ToString() == "T" || _record[0].ToString() == "P")
  87. {
  88. _totalAmount += Convert.ToDecimal(_record[11]);
  89. }
  90. }
  91. if (_fileTotal != _totalAmount)
  92. {
  93. TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName (" +
  94. _fileTotal.ToString() +
  95. ") is diffrent with file content (" + _totalAmount.ToString() +
  96. ".");
  97. }
  98. else
  99. {
  100. Status _insertMessage = new Status();
  101. if (Common.IsInActiveDate(_arrayFileName[2]))
  102. {
  103. _insertMessage = Settlement.Inserts(_dataExcel);
  104. }
  105. else
  106. {
  107. _insertMessage = Settlement.Inserts(_dataExcel, true);
  108. }
  109. if (_insertMessage.StatusValue)
  110. {
  111. TReadingLog.Add(e.Name, "Success", "Data settlement has been
  112. inserted. " + _insertMessage.Remark);
  113. }
  114. else
  115. {
  116. TReadingLog.Add(e.Name, "Failed", "Data settlement failed to be
  117. inserted. " + _insertMessage.Remark);
  118. }
  119. }
  120. }
  121. }
  122. else
  123. {
  124. _lastFTPTime = DateTime.MinValue;
  125. }
  126.  
  127. }
  128. }
  129. catch (Exception _error)
  130. {
  131. TLog.Add("HCCPReader.HCCPReader.fswFtp_Changed", _error.Message);
  132. }
  133. finally
  134. {
  135. _dataExcel.Dispose();
  136. }
  137. }
  138.  
  139. private void fswUpload_Changed(object sender, FileSystemEventArgs e)
  140. {
  141. DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
  142. DataTable _dataExcel = new DataTable();
  143. try
  144. {
  145. if (_fswFileTime _lastFTPTime)
  146. {
  147. _lastFTPTime = _fswFileTime;
  148. bool _isFileComplete = Common.IsFileCompete(e.FullPath);
  149. int _tries = 0;
  150. while (!_isFileComplete && _tries < 15)
  151. {
  152. System.Threading.Thread.Sleep(1000);
  153. _tries++;
  154. _isFileComplete = Common.IsFileCompete(e.FullPath);
  155. }
  156. if (_isFileComplete)
  157. {
  158. //here sistem to read excel file
  159. _dataExcel = Reading.GetDataExcel(e.FullPath);
  160. //column 10
  161. string[] _arrayFileName = e.Name.Split('_');
  162. Decimal _fileTotal = 0;
  163. Decimal _totalAmount = 0;
  164. try
  165. {
  166. _fileTotal = Convert.ToDecimal(_arrayFileName[3]);
  167. }
  168. catch
  169. {
  170. _fileTotal = -1;
  171. TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
  172. with file name template.");
  173. }
  174. if (_fileTotal != -1)
  175. {
  176. foreach (DataRow _record in _dataExcel.Rows)
  177. {
  178. if (_record[0].ToString() == "S" || _record[0].ToString() == "Z" ||
  179. _record[0].ToString() == "T" || _record[0].ToString() == "P")
  180. {
  181. _totalAmount += Convert.ToDecimal(_record[11]);
  182. }
  183. }
  184. if (_fileTotal != _totalAmount)
  185. {
  186. TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName (" +
  187. _fileTotal.ToString() +
  188. ") is diffrent with file content (" + _totalAmount.ToString() +
  189. ".");
  190. }
  191. else
  192. {
  193. Status _insertMessage = new Status();
  194. if (Common.IsInActiveDate(_arrayFileName[2]))
  195. {
  196. _insertMessage = Settlement.Inserts(_dataExcel);
  197. }
  198. else
  199. {
  200. _insertMessage = Settlement.Inserts(_dataExcel, true);
  201. }
  202. if (_insertMessage.StatusValue)
  203. {
  204. TReadingLog.Add(e.Name, "Success", "Data settlement has been
  205. inserted. " + _insertMessage.Remark);
  206. }
  207. else
  208. {
  209. TReadingLog.Add(e.Name, "Failed", "Data settlement failed to be
  210. inserted. " + _insertMessage.Remark);
  211. }
  212. }
  213. }
  214. }
  215. else
  216. {
  217. _lastFTPTime = DateTime.MinValue;
  218. }
  219.  
  220. }
  221. }
  222. catch (Exception _error)
  223. {
  224. TLog.Add("HCCPReader.HCCPReader.fswUpload_Changed", _error.Message);
  225. }
  226. finally
  227. {
  228. _dataExcel.Dispose();
  229. }
  230. }
  231.  
  232. private void fswFtp_Created(object sender, FileSystemEventArgs e)
  233. {
  234. DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
  235. DataTable _dataExcel = new DataTable();
  236. try
  237. {
  238. bool _isFileComplete = Common.IsFileCompete(e.FullPath);
  239. if (_isFileComplete)
  240. {
  241. //here sistem to read excel file
  242. _dataExcel = Reading.GetDataExcel(e.FullPath);
  243. string[] _arrayFileName = e.Name.Split('_');
  244. Decimal _fileTotal = 0;
  245. Decimal _totalAmount = 0;
  246. try
  247. {
  248. _fileTotal = Convert.ToDecimal(_arrayFileName[3]);
  249. }
  250. catch
  251. {
  252. _fileTotal = -1;
  253. TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
  254. with file name template.");
  255. }
  256. if (_fileTotal != -1)
  257. {
  258. foreach (DataRow _record in _dataExcel.Rows)
  259. {
  260. if (_record[0].ToString() == "S" || _record[0].ToString() == "Z"
  261. || _record[0].ToString() == "T" || _record[0].ToString() == "P")
  262. {
  263. _totalAmount += Convert.ToDecimal(_record[11]);
  264. }
  265. }
  266. if (_fileTotal != _totalAmount)
  267. {
  268. TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName
  269. (" + _fileTotal.ToString() +
  270. ") is diffrent with file content (" + _totalAmount.ToString() +
  271. ".");
  272. }
  273. else
  274. {
  275. Status _insertMessage = new Status();
  276. if (Common.IsInActiveDate(_arrayFileName[2]))
  277. {
  278. _insertMessage = Settlement.Inserts(_dataExcel);
  279. }
  280. else
  281. {
  282. _insertMessage = Settlement.Inserts(_dataExcel, true);
  283. }
  284. if (_insertMessage.StatusValue)
  285. {
  286. TReadingLog.Add(e.Name, "Success", "Data settlement has been
  287. inserted. " + _insertMessage.Remark);
  288. }
  289. else
  290. {
  291. TReadingLog.Add(e.Name, "Failed", "Data settlement failed to be
  292. inserted. " + _insertMessage.Remark);
  293. }
  294. }
  295. }
  296. }
  297. }
  298. catch (Exception _error)
  299. {
  300. TLog.Add("HCCPReader.HCCPReader.fswFtp_Created", _error.Message);
  301. }
  302. finally
  303. {
  304. _dataExcel.Dispose();
  305. }
  306. }
  307.  
  308. private void fswUpload_Created(object sender, FileSystemEventArgs e)
  309. {
  310. DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
  311. DataTable _dataExcel = new DataTable();
  312. try
  313. {
  314. bool _isFileComplete = Common.IsFileCompete(e.FullPath);
  315. if (_isFileComplete)
  316. {
  317. //here sistem to read excel file
  318. _dataExcel = Reading.GetDataExcel(e.FullPath);
  319. string[] _arrayFileName = e.Name.Split('_');
  320. Decimal _fileTotal = 0;
  321. Decimal _totalAmount = 0;
  322. try
  323. {
  324. _fileTotal = Convert.ToDecimal(_arrayFileName[3]);
  325. }
  326. catch
  327. {
  328. _fileTotal = -1;
  329. TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
  330. with file name template.");
  331. }
  332. if (_fileTotal != -1)
  333. {
  334. foreach (DataRow _record in _dataExcel.Rows)
  335. {
  336. if (_record[0].ToString() == "S" || _record[0].ToString() == "Z"
  337. || _record[0].ToString() == "T" || _record[0].ToString() == "P")
  338. {
  339. _totalAmount += Convert.ToDecimal(_record[11]);
  340. }
  341. }
  342. if (_fileTotal != _totalAmount)
  343. {
  344. TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName
  345. (" + _fileTotal.ToString() +
  346. ") is diffrent with file content (" + _totalAmount.ToString() +
  347. ".");
  348. }
  349. else
  350. {
  351.  
  352. Status _insertMessage = new Status();
  353. if(Common.IsInActiveDate(_arrayFileName[2]))
  354. {
  355. _insertMessage=Settlement.Inserts(_dataExcel);
  356. }
  357. else
  358. {
  359. _insertMessage=Settlement.Inserts(_dataExcel,true);
  360. }
  361. if (_insertMessage.StatusValue)
  362. {
  363. TReadingLog.Add(e.Name,"Success", "Data settlement has been
  364. inserted. " + _insertMessage.Remark);
  365. }
  366. else
  367. {
  368. TReadingLog.Add(e.Name,"Failed", "Data settlement failed to be
  369. inserted. " + _insertMessage.Remark);
  370. }
  371. }
  372. }
  373. }
  374. }
  375. catch (Exception _error)
  376. {
  377. TLog.Add("HCCPReader.HCCPReader.fswUpload_Created", _error.Message);
  378. }
  379. finally
  380. {
  381. _dataExcel.Dispose();
  382. }
  383. }
  384.  
  385. private void fswBankNotify_Changed(object sender, FileSystemEventArgs
  386. e)
  387. {
  388. DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
  389. DataTable _dataExcel = new DataTable();
  390. try
  391. {
  392. if (_fswFileTime _lastBankUploadTime)
  393. {
  394. _lastBankUploadTime = _fswFileTime;
  395. bool _isFileComplete = Common.IsFileCompete(e.FullPath);
  396. int _tries = 0;
  397. while (!_isFileComplete && _tries < 15)
  398. {
  399. System.Threading.Thread.Sleep(1000);
  400. _tries++;
  401. _isFileComplete = Common.IsFileCompete(e.FullPath);
  402. }
  403. if (_isFileComplete)
  404. {
  405. //here sistem to read excel file
  406. _dataExcel = Reading.GetDataExcel(e.FullPath);
  407. Status _insertMessage = new Status();
  408. _insertMessage = BankNotification.Process(_dataExcel);
  409. if (_insertMessage.StatusValue)
  410. {
  411. TReadingLog.Add(e.Name, "Success", "Data bank notification
  412. berhasil diinput. " + _insertMessage.Remark);
  413. }
  414. else
  415. {
  416. TReadingLog.Add(e.Name, "Failed", "Data bank notification gagal
  417. diinput. " + _insertMessage.Remark);
  418. }
  419. FileInfo _fileInfo = new FileInfo(e.FullPath);
  420. TTempBankNotification.UpdateStatus(_fileInfo.DirectoryName,
  421. _insertMessage);
  422. File.Delete(e.FullPath);
  423. }
  424. else
  425. {
  426. _lastFTPTime = DateTime.MinValue;
  427. }
  428. }
  429. }
  430. catch (Exception _error)
  431. {
  432. TLog.Add("HCCPReader.HCCPReader.fswBankNotify_Changed",
  433. _error.Message);
  434. }
  435. finally
  436. {
  437. _dataExcel.Dispose();
  438. }
  439. }
  440.  
  441. private void fswBankNotify_Created(object sender, FileSystemEventArgs
  442. e)
  443. {
  444. DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
  445. DataTable _dataExcel = new DataTable();
  446. try
  447. {
  448. bool _isFileComplete = Common.IsFileCompete(e.FullPath);
  449. if (_isFileComplete)
  450. {
  451. //here sistem to read excel file
  452. _dataExcel = Reading.GetDataExcel(e.FullPath);
  453. Status _insertMessage = new Status();
  454. _insertMessage = BankNotification.Process(_dataExcel);
  455. if (_insertMessage.StatusValue)
  456. {
  457. TReadingLog.Add(e.Name, "Success", "Data bank notification berhasil
  458. diinput. " + _insertMessage.Remark);
  459. }
  460. else
  461. {
  462. TReadingLog.Add(e.Name, "Failed", "Data bank notification gagal
  463. diinput. " + _insertMessage.Remark);
  464. }
  465. FileInfo _fileInfo= new FileInfo(e.FullPath);
  466. TTempBankNotification.UpdateStatus(_fileInfo.DirectoryName,
  467. _insertMessage);
  468. File.Delete(e.FullPath);
  469. }
  470. }
  471. catch (Exception _error)
  472. {
  473. TLog.Add("HCCPReader.HCCPReader.fswBankNotify_Created",
  474. _error.Message);
  475. }
  476. finally
  477. {
  478. _dataExcel.Dispose();
  479. }
  480. }
  481. }
  482.  
  483.  
My code just run well on MS XP, but it has this problem on MS Server
2003
Jul 14 '08 #6

P: n/a
Thanks all for your quict reply

this is my snipped code ( I just translate it because i use my on
language)
Expand|Select|Wrap|Line Numbers
  1. public partial class HCCPReader : ServiceBase
  2. {
  3. DateTime _lastFileTime = DateTime.MinValue;
  4. protected DateTime _lastFTPTime = DateTime.MinValue;
  5. protected DateTime _lastUploadTime = DateTime.MinValue;
  6. protected DateTime _lastBankUploadTime = DateTime.MinValue;
  7.  
  8. System.Timers.Timer _newTimer = new System.Timers.Timer();
  9.  
  10. public HCCPReader()
  11. {
  12. InitializeComponent();
  13. }
  14.  
  15. protected override void OnStart(string[] args)
  16. {
  17. // TODO: Add code here to start your service.
  18. _lastFileTime = DateTime.MinValue;
  19. fswUpload.Path = Common.GetUploadSettlementPath();
  20. fswUpload.EnableRaisingEvents = true;
  21. fswFtp.Path = Common.GetFTPPath();
  22. fswFtp.EnableRaisingEvents = true;
  23. fswBankNotify.Path = Common.GetUploadBankPath();
  24. fswBankNotify.EnableRaisingEvents=true;
  25. _newTimer.Interval =3600000;
  26. _newTimer.Elapsed += new
  27. System.Timers.ElapsedEventHandler(ServiceTimer_Tick);
  28. }
  29.  
  30. protected override void OnStop()
  31. {
  32. // TODO: Add code here to perform any tear-down necessary to stop
  33. your service.
  34. fswUpload.EnableRaisingEvents = false;
  35. fswFtp.EnableRaisingEvents = false;
  36. fswBankNotify.EnableRaisingEvents = false;
  37. }
  38.  
  39. private void ServiceTimer_Tick(object sender,
  40. System.Timers.ElapsedEventArgs e)
  41. {
  42. SunFile.Clear();
  43. Clear.ClearDirectory();
  44. }
  45. private void fswFtp_Changed(object sender,
  46. System.IO.FileSystemEventArgs e)
  47. {
  48. DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
  49. DataTable _dataExcel = new DataTable();
  50. try
  51. {
  52. if (_fswFileTime _lastFTPTime)
  53. {
  54. _lastFTPTime = _fswFileTime;
  55. bool _isFileComplete = Common.IsFileCompete(e.FullPath);
  56. int _tries = 0;
  57. while (!_isFileComplete && _tries < 15)
  58. {
  59. System.Threading.Thread.Sleep(1000);
  60. _tries++;
  61. _isFileComplete = Common.IsFileCompete(e.FullPath);
  62. }
  63. if (_isFileComplete)
  64. {
  65. //here sistem to read excel file
  66. _dataExcel = Reading.GetDataExcel(e.FullPath);
  67. //column 10
  68. string[] _arrayFileName = e.Name.Split('_');
  69. Decimal _fileTotal = 0;
  70. Decimal _totalAmount = 0;
  71. try
  72. {
  73. _fileTotal = Convert.ToDecimal(_arrayFileName[3]);
  74. }
  75. catch
  76. {
  77. _fileTotal = -1;
  78. TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
  79. with file name template.");
  80. }
  81. if (_fileTotal != -1)
  82. {
  83. foreach (DataRow _record in _dataExcel.Rows)
  84. {
  85. if (_record[0].ToString() == "S" || _record[0].ToString() == "Z" ||
  86. _record[0].ToString() == "T" || _record[0].ToString() == "P")
  87. {
  88. _totalAmount += Convert.ToDecimal(_record[11]);
  89. }
  90. }
  91. if (_fileTotal != _totalAmount)
  92. {
  93. TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName (" +
  94. _fileTotal.ToString() +
  95. ") is diffrent with file content (" + _totalAmount.ToString() +
  96. ".");
  97. }
  98. else
  99. {
  100. Status _insertMessage = new Status();
  101. if (Common.IsInActiveDate(_arrayFileName[2]))
  102. {
  103. _insertMessage = Settlement.Inserts(_dataExcel);
  104. }
  105. else
  106. {
  107. _insertMessage = Settlement.Inserts(_dataExcel, true);
  108. }
  109. if (_insertMessage.StatusValue)
  110. {
  111. TReadingLog.Add(e.Name, "Success", "Data settlement has been
  112. inserted. " + _insertMessage.Remark);
  113. }
  114. else
  115. {
  116. TReadingLog.Add(e.Name, "Failed", "Data settlement failed to be
  117. inserted. " + _insertMessage.Remark);
  118. }
  119. }
  120. }
  121. }
  122. else
  123. {
  124. _lastFTPTime = DateTime.MinValue;
  125. }
  126.  
  127. }
  128. }
  129. catch (Exception _error)
  130. {
  131. TLog.Add("HCCPReader.HCCPReader.fswFtp_Changed", _error.Message);
  132. }
  133. finally
  134. {
  135. _dataExcel.Dispose();
  136. }
  137. }
  138.  
  139. private void fswUpload_Changed(object sender, FileSystemEventArgs e)
  140. {
  141. DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
  142. DataTable _dataExcel = new DataTable();
  143. try
  144. {
  145. if (_fswFileTime _lastFTPTime)
  146. {
  147. _lastFTPTime = _fswFileTime;
  148. bool _isFileComplete = Common.IsFileCompete(e.FullPath);
  149. int _tries = 0;
  150. while (!_isFileComplete && _tries < 15)
  151. {
  152. System.Threading.Thread.Sleep(1000);
  153. _tries++;
  154. _isFileComplete = Common.IsFileCompete(e.FullPath);
  155. }
  156. if (_isFileComplete)
  157. {
  158. //here sistem to read excel file
  159. _dataExcel = Reading.GetDataExcel(e.FullPath);
  160. //column 10
  161. string[] _arrayFileName = e.Name.Split('_');
  162. Decimal _fileTotal = 0;
  163. Decimal _totalAmount = 0;
  164. try
  165. {
  166. _fileTotal = Convert.ToDecimal(_arrayFileName[3]);
  167. }
  168. catch
  169. {
  170. _fileTotal = -1;
  171. TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
  172. with file name template.");
  173. }
  174. if (_fileTotal != -1)
  175. {
  176. foreach (DataRow _record in _dataExcel.Rows)
  177. {
  178. if (_record[0].ToString() == "S" || _record[0].ToString() == "Z" ||
  179. _record[0].ToString() == "T" || _record[0].ToString() == "P")
  180. {
  181. _totalAmount += Convert.ToDecimal(_record[11]);
  182. }
  183. }
  184. if (_fileTotal != _totalAmount)
  185. {
  186. TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName (" +
  187. _fileTotal.ToString() +
  188. ") is diffrent with file content (" + _totalAmount.ToString() +
  189. ".");
  190. }
  191. else
  192. {
  193. Status _insertMessage = new Status();
  194. if (Common.IsInActiveDate(_arrayFileName[2]))
  195. {
  196. _insertMessage = Settlement.Inserts(_dataExcel);
  197. }
  198. else
  199. {
  200. _insertMessage = Settlement.Inserts(_dataExcel, true);
  201. }
  202. if (_insertMessage.StatusValue)
  203. {
  204. TReadingLog.Add(e.Name, "Success", "Data settlement has been
  205. inserted. " + _insertMessage.Remark);
  206. }
  207. else
  208. {
  209. TReadingLog.Add(e.Name, "Failed", "Data settlement failed to be
  210. inserted. " + _insertMessage.Remark);
  211. }
  212. }
  213. }
  214. }
  215. else
  216. {
  217. _lastFTPTime = DateTime.MinValue;
  218. }
  219.  
  220. }
  221. }
  222. catch (Exception _error)
  223. {
  224. TLog.Add("HCCPReader.HCCPReader.fswUpload_Changed", _error.Message);
  225. }
  226. finally
  227. {
  228. _dataExcel.Dispose();
  229. }
  230. }
  231.  
  232. private void fswFtp_Created(object sender, FileSystemEventArgs e)
  233. {
  234. DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
  235. DataTable _dataExcel = new DataTable();
  236. try
  237. {
  238. bool _isFileComplete = Common.IsFileCompete(e.FullPath);
  239. if (_isFileComplete)
  240. {
  241. //here sistem to read excel file
  242. _dataExcel = Reading.GetDataExcel(e.FullPath);
  243. string[] _arrayFileName = e.Name.Split('_');
  244. Decimal _fileTotal = 0;
  245. Decimal _totalAmount = 0;
  246. try
  247. {
  248. _fileTotal = Convert.ToDecimal(_arrayFileName[3]);
  249. }
  250. catch
  251. {
  252. _fileTotal = -1;
  253. TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
  254. with file name template.");
  255. }
  256. if (_fileTotal != -1)
  257. {
  258. foreach (DataRow _record in _dataExcel.Rows)
  259. {
  260. if (_record[0].ToString() == "S" || _record[0].ToString() == "Z"
  261. || _record[0].ToString() == "T" || _record[0].ToString() == "P")
  262. {
  263. _totalAmount += Convert.ToDecimal(_record[11]);
  264. }
  265. }
  266. if (_fileTotal != _totalAmount)
  267. {
  268. TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName
  269. (" + _fileTotal.ToString() +
  270. ") is diffrent with file content (" + _totalAmount.ToString() +
  271. ".");
  272. }
  273. else
  274. {
  275. Status _insertMessage = new Status();
  276. if (Common.IsInActiveDate(_arrayFileName[2]))
  277. {
  278. _insertMessage = Settlement.Inserts(_dataExcel);
  279. }
  280. else
  281. {
  282. _insertMessage = Settlement.Inserts(_dataExcel, true);
  283. }
  284. if (_insertMessage.StatusValue)
  285. {
  286. TReadingLog.Add(e.Name, "Success", "Data settlement has been
  287. inserted. " + _insertMessage.Remark);
  288. }
  289. else
  290. {
  291. TReadingLog.Add(e.Name, "Failed", "Data settlement failed to be
  292. inserted. " + _insertMessage.Remark);
  293. }
  294. }
  295. }
  296. }
  297. }
  298. catch (Exception _error)
  299. {
  300. TLog.Add("HCCPReader.HCCPReader.fswFtp_Created", _error.Message);
  301. }
  302. finally
  303. {
  304. _dataExcel.Dispose();
  305. }
  306. }
  307.  
  308. private void fswUpload_Created(object sender, FileSystemEventArgs e)
  309. {
  310. DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
  311. DataTable _dataExcel = new DataTable();
  312. try
  313. {
  314. bool _isFileComplete = Common.IsFileCompete(e.FullPath);
  315. if (_isFileComplete)
  316. {
  317. //here sistem to read excel file
  318. _dataExcel = Reading.GetDataExcel(e.FullPath);
  319. string[] _arrayFileName = e.Name.Split('_');
  320. Decimal _fileTotal = 0;
  321. Decimal _totalAmount = 0;
  322. try
  323. {
  324. _fileTotal = Convert.ToDecimal(_arrayFileName[3]);
  325. }
  326. catch
  327. {
  328. _fileTotal = -1;
  329. TReadingLog.Add(e.Name, "Wrong Template", "File name is not same
  330. with file name template.");
  331. }
  332. if (_fileTotal != -1)
  333. {
  334. foreach (DataRow _record in _dataExcel.Rows)
  335. {
  336. if (_record[0].ToString() == "S" || _record[0].ToString() == "Z"
  337. || _record[0].ToString() == "T" || _record[0].ToString() == "P")
  338. {
  339. _totalAmount += Convert.ToDecimal(_record[11]);
  340. }
  341. }
  342. if (_fileTotal != _totalAmount)
  343. {
  344. TReadingLog.Add(e.Name, "Diference Amount", "Total on FileName
  345. (" + _fileTotal.ToString() +
  346. ") is diffrent with file content (" + _totalAmount.ToString() +
  347. ".");
  348. }
  349. else
  350. {
  351.  
  352. Status _insertMessage = new Status();
  353. if(Common.IsInActiveDate(_arrayFileName[2]))
  354. {
  355. _insertMessage=Settlement.Inserts(_dataExcel);
  356. }
  357. else
  358. {
  359. _insertMessage=Settlement.Inserts(_dataExcel,true);
  360. }
  361. if (_insertMessage.StatusValue)
  362. {
  363. TReadingLog.Add(e.Name,"Success", "Data settlement has been
  364. inserted. " + _insertMessage.Remark);
  365. }
  366. else
  367. {
  368. TReadingLog.Add(e.Name,"Failed", "Data settlement failed to be
  369. inserted. " + _insertMessage.Remark);
  370. }
  371. }
  372. }
  373. }
  374. }
  375. catch (Exception _error)
  376. {
  377. TLog.Add("HCCPReader.HCCPReader.fswUpload_Created", _error.Message);
  378. }
  379. finally
  380. {
  381. _dataExcel.Dispose();
  382. }
  383. }
  384.  
  385. private void fswBankNotify_Changed(object sender, FileSystemEventArgs
  386. e)
  387. {
  388. DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
  389. DataTable _dataExcel = new DataTable();
  390. try
  391. {
  392. if (_fswFileTime _lastBankUploadTime)
  393. {
  394. _lastBankUploadTime = _fswFileTime;
  395. bool _isFileComplete = Common.IsFileCompete(e.FullPath);
  396. int _tries = 0;
  397. while (!_isFileComplete && _tries < 15)
  398. {
  399. System.Threading.Thread.Sleep(1000);
  400. _tries++;
  401. _isFileComplete = Common.IsFileCompete(e.FullPath);
  402. }
  403. if (_isFileComplete)
  404. {
  405. //here sistem to read excel file
  406. _dataExcel = Reading.GetDataExcel(e.FullPath);
  407. Status _insertMessage = new Status();
  408. _insertMessage = BankNotification.Process(_dataExcel);
  409. if (_insertMessage.StatusValue)
  410. {
  411. TReadingLog.Add(e.Name, "Success", "Data bank notification
  412. berhasil diinput. " + _insertMessage.Remark);
  413. }
  414. else
  415. {
  416. TReadingLog.Add(e.Name, "Failed", "Data bank notification gagal
  417. diinput. " + _insertMessage.Remark);
  418. }
  419. FileInfo _fileInfo = new FileInfo(e.FullPath);
  420. TTempBankNotification.UpdateStatus(_fileInfo.DirectoryName,
  421. _insertMessage);
  422. File.Delete(e.FullPath);
  423. }
  424. else
  425. {
  426. _lastFTPTime = DateTime.MinValue;
  427. }
  428. }
  429. }
  430. catch (Exception _error)
  431. {
  432. TLog.Add("HCCPReader.HCCPReader.fswBankNotify_Changed",
  433. _error.Message);
  434. }
  435. finally
  436. {
  437. _dataExcel.Dispose();
  438. }
  439. }
  440.  
  441. private void fswBankNotify_Created(object sender, FileSystemEventArgs
  442. e)
  443. {
  444. DateTime _fswFileTime = File.GetLastAccessTime(e.FullPath);
  445. DataTable _dataExcel = new DataTable();
  446. try
  447. {
  448. bool _isFileComplete = Common.IsFileCompete(e.FullPath);
  449. if (_isFileComplete)
  450. {
  451. //here sistem to read excel file
  452. _dataExcel = Reading.GetDataExcel(e.FullPath);
  453. Status _insertMessage = new Status();
  454. _insertMessage = BankNotification.Process(_dataExcel);
  455. if (_insertMessage.StatusValue)
  456. {
  457. TReadingLog.Add(e.Name, "Success", "Data bank notification berhasil
  458. diinput. " + _insertMessage.Remark);
  459. }
  460. else
  461. {
  462. TReadingLog.Add(e.Name, "Failed", "Data bank notification gagal
  463. diinput. " + _insertMessage.Remark);
  464. }
  465. FileInfo _fileInfo= new FileInfo(e.FullPath);
  466. TTempBankNotification.UpdateStatus(_fileInfo.DirectoryName,
  467. _insertMessage);
  468. File.Delete(e.FullPath);
  469. }
  470. }
  471. catch (Exception _error)
  472. {
  473. TLog.Add("HCCPReader.HCCPReader.fswBankNotify_Created",
  474. _error.Message);
  475. }
  476. finally
  477. {
  478. _dataExcel.Dispose();
  479. }
  480. }
  481. }
  482.  
  483.  
My code just run well on MS XP, but it has this problem on MS Server
2003
Jul 14 '08 #7

P: n/a
On Jul 13, 2:50*pm, Jeroen Mostert <jmost...@xs4all.nlwrote:
Brian Gideon wrote:
On Jul 13, 5:43 am, Jeroen Mostert <jmost...@xs4all.nlwrote:
Lemune wrote:
I'm developing window service application on C# 2005.
The service is to read a new excel file on certain directory, and
process it to database.
The service work find on XP.
But when I install the application on Windows Server 2003, when i
start the service it said:
"The <my serviceon Local Computer started and then stop. Some
service stop automatically if they have no work to do , for example ,
the Performance Logs and Alerts System."
This means your service crashed during startup, which could have any number
of causes. Consult the event log for more details, and hook up an event
handler to AppDomain.UnhandledException in your service that logs to afile.
I can't remember for certain, but it sounds more like the service
stopped by choice. *When a service crashes or throws an exception you
get a message stating that the service failed to start altogether.

Not on Windows XP, at least; I tested it. If the service throws an exception
in its OnStart(), you'll get the exact message the OP described. The event
log will contain the exception details.

A .NET service can't really stop by choice, except through calling
Environment.Exit() (or by explicitly connecting to the SCM and stopping
itself, but that's just backwards).

--
J.
Yep, I tested it too. You are correct. I guess my memory isn't that
good :)
Jul 14 '08 #8

P: n/a
Thanks Jeroen,

I check event log, and I have found my error.
It's just because the my exe config that has some error.
I have fixed my problem.

Thanks all.
Jul 15 '08 #9

This discussion thread is closed

Replies have been disabled for this discussion.