线程,数据库访问和文本文件中的澄清 [英] Clarification in Thread, database Access and Text file
问题描述
Hi Developers,
我正在我的代码中处理2个线程.
1.处理我的申请.
2.处理计划.
1.问题
----------
两个线程都将进程信息记录到记事本中.
有时两个线程都尝试访问相同的记事本文件并引发错误.如何克服这个错误.
2.问题
-----------
一个. Scheduler收集数据库的日期和时间每1分钟一次.因此增加网络流量的原因
b. Scheduler收集数据库的日期和时间一次,我正在检查本地系统的日期和时间并进行匹配.在这种情况下,如果客户端系统日期相差很大,则会出现问题.
这两个问题有更好的解决方案吗?
问候,
Nanda
Hi Developers,
I am handling 2 thread in my code.
1. Handle my application.
2. Handle Scheduling.
1. Problem
----------
Both Thread logging process information into notepad.
Some time both thread try to access same notepad file and throwing error. how to overcome from this error.
2. Problem
-----------
a. The Scheduler collection database date & time every 1 min. that reason it increasing network traffic
b. The Scheduler collection database date & time once and I am checking with local system date & time and matching. In this case If client system date have huge difference it giving problem.
Is there any better solution for this two problem?
Regards,
Nanda
推荐答案
是的,您可以并且应该使用更好的解决方案.
#1.很难发明出比登录记事本更糟糕的东西.使用类System.EventLog
登录到系统日志.
请在这些问题的页面上查看有关EventLog
的高级示例和建议:
如何在文件夹下创建事件日志 [ ^ ]
将MsBuild OutPut即时发送到TextBox Windows应用程序中 [ ^ ]
#2.最好不要使用计时器.实际上,请务必避免.很难避免几种问题.使用线程定期轮询数据库.创建一个单独的线程并永久使用它.轮询周期将由System.Threading.Thread.Sleep
定义.
我在这里收集了我过去关于线程和调用的答案(需要使用UI)的基本参考:
如何获取keydown事件在vb.net中的不同线程上操作 [
Yes, you can and should use better solution.
#1. Hard to invent anything worse that logging into Notepad. Log to system log using the classSystem.EventLog
.
Please see my advanced samples and advices onEventLog
in the pages on these Questions:
How to create event log under a folder[^]
MsBuild OutPut to the TextBox on the fly in Windows Application[^]
#2. Prefer not using timer. Actually, avoid it by all means. It''s very hard to avoid several kinds of problems. Use a thread periodically polling your database. Create a separate thread and permanently use it. The period of polling will be defined bySystem.Threading.Thread.Sleep
.
I collected essential references to my past Answers on threading and Invocation (needed to use UI) here:
How to get a keydown event to operate on a different thread in vb.net[^]
If you need some motivation of these approaches, I''ll answer separately. I also have a collection of directions and samples on threading and logging from my past Answers, but all in C# (but more in English :-) … Well, to get good help on .NET and code samples you need at least some understanding of C#, anyway.
I added some references to past Answers. You can ignore the fact that applications are very different. Most advices will be quite applicable to yours. Feel free to ask follow-up Questions.
—SA
这篇关于线程,数据库访问和文本文件中的澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!