Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 16-Mar-11 6:16am
v2
Comments
Sergey Alexandrovich Kryukov 16-Mar-11 12:18pm    
"Clearification" was interesting neologism, but traditional correct boring spelling is better. :-)
Watch this: http://www.youtube.com/watch?v=u9_kahA_wQo
--SA

1 solution

Yes, you can and should use better solution.

#1. Hard to invent anything worse that logging into Notepad. Log to system log using the class System.EventLog.

Please see my advanced samples and advices on EventLog 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 by System.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
 
Share this answer
 
v3
Comments
Nanda_MR 16-Mar-11 2:00am    
Hey Thanks,

1. The Logging information is more. it store executed query, error, Warning, Information, Database Logging information and some import parameter.
Per month I create many more than 100 log and file size approx. 2 to 5 MB.

2. I will try Thread.

*if you have solution in C# send me. I can understand.
Sergey Alexandrovich Kryukov 16-Mar-11 3:12am    
Ok, see updated Answer. If I'll update anything, I'll notify you. You also need general introductory/overview material on threading. Use my keywords, go to MSDN and from MSDN articles get references to overview and technology walk-through chapters. Ask further Questions, but my time will be limited.
--SA
Sandeep Mewara 16-Mar-11 5:08am    
5++ answer! :)
Sergey Alexandrovich Kryukov 16-Mar-11 5:12am    
Thank you, Sandeep,
--SA
Nuri Ismail 16-Mar-11 5:26am    
Great answer! 5+ :)

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