Article View: borland.public.cppbuilder.nativeapi
Article #2208Re: File Creation and contention
From: DreamChaser
Date: Fri, 23 Mar 2007 05:33
Date: Fri, 23 Mar 2007 05:33
25 lines
1853 bytes
1853 bytes
John Grabner wrote: > I need to create a log file. There may be several process that want to > write to the log file. When creating the log file how do I make sure > that only one process creates the file? > > John. I am sure someone with A LOT more experience will pipe in on this, but I got here first :) When you say "processes", do you mean threads within your single application? If so, then you could wrap your logging code in critical sections. If not. Maybe some use of FileOpen() for exclusive use. Another option that I just remembered. You could create a class that handles ALL of the logging. Each process could post it's message to a TStringList property of the class. Then every so often the clas could open the log file, write out everything, then close the file. Just some random thoughts... Hope it helps, or at least points you in the right irection. God Luck. DC
Technical Details
Message-ID:
<46036690$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<4603628f$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10cc67,5d20743a8be4a735 X-Google-Attributes: gid10cc67,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Fri, 23 Mar 2007 00:33:06 -0500 From: DreamChaser <NO-Spam@No-Span.net> User-Agent: Thunderbird 1.5.0.10 (Windows/20070221) MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: File Creation and contention References: <4603628f$1@newsgroups.borland.com> In-Reply-To: <4603628f$1@newsgroups.borland.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 65.6.192.60 Message-ID: <46036690$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1174627984 65.6.192.60 (22 Mar 2007 22:33:04 -0800) Lines: 25 Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail