473,769 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Share thread among objects

Hi,
I'm logging the values my app is producing, in order to keep the logs small
I zip them hourly.
My problem lies in that two (or more) different objects discover that the
hour has changed and each tries to start a thread to create the hourly zip.
The runner up discovers that there is no file and creates it, but during
this time the first thread already has created the file and I get an "File
already exists"-error.

Basically, I want the object that first discovers a change of hour to start
a single thread where the zip occurs. The runner up object should notice
that the thread is started/zip exists and just add the previous log file to
the zip.

TIA
Kejpa
Nov 21 '05 #1
7 1167
Kepja,

My simple answer is catch that error and close the thread.

What am I missing with this answer?

Cor

"Kejpa" <kS*******@saj. fi>
Hi,
I'm logging the values my app is producing, in order to keep the logs
small
I zip them hourly.
My problem lies in that two (or more) different objects discover that the
hour has changed and each tries to start a thread to create the hourly
zip.
The runner up discovers that there is no file and creates it, but during
this time the first thread already has created the file and I get an "File
already exists"-error.

Basically, I want the object that first discovers a change of hour to
start
a single thread where the zip occurs. The runner up object should notice
that the thread is started/zip exists and just add the previous log file
to
the zip.

TIA
Kejpa

Nov 21 '05 #2

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:OT******** *****@TK2MSFTNG P11.phx.gbl...
Kepja,

My simple answer is catch that error and close the thread.

What am I missing with this answer?


Probably nothing. I was just not sure wheather or not that was the
best/cleanest way to do it...

/Kejpa
Nov 21 '05 #3
Kejpa,
Is each object running in their own thread?

I would consider separating the logic that creates the zip file from the
objects themselves. Let the objects themselves simply write to the log file.

I would then use either the System.Timers.T imer.Elapsed event or a
System.Threadin g.Timer callback to start the zip method.
Alternatively you can use one or more SyncLock statements to ensure that
only a single Thread is zipping the file at a time. Primarily you want a
SyncLock around the time check to see if zipping needs to occur. I would
consider putting a separate SyncLock (on a different lock object) around the
zipping itself, just to be certain.

Hope this helps
Jay
"Kejpa" <kS*******@saj. fi> wrote in message
news:cm******** **@gandalf.alco m.aland.fi...
Hi,
I'm logging the values my app is producing, in order to keep the logs
small
I zip them hourly.
My problem lies in that two (or more) different objects discover that the
hour has changed and each tries to start a thread to create the hourly
zip.
The runner up discovers that there is no file and creates it, but during
this time the first thread already has created the file and I get an "File
already exists"-error.

Basically, I want the object that first discovers a change of hour to
start
a single thread where the zip occurs. The runner up object should notice
that the thread is started/zip exists and just add the previous log file
to
the zip.

TIA
Kejpa

Nov 21 '05 #4
Kepja,

I have assumed from your messages that the information in both Zip files is
absolute the same and that it is exactly the same kind of process that
starts in almost the same time.

Before we understand each other wrong.

Cor
"Kejpa" <kS*******@saj. fi>

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:OT******** *****@TK2MSFTNG P11.phx.gbl...
Kepja,

My simple answer is catch that error and close the thread.

What am I missing with this answer?


Probably nothing. I was just not sure wheather or not that was the
best/cleanest way to do it...

/Kejpa

Nov 21 '05 #5
Yes,
there will be one zip-file per hour.
The objects all write to the same log file and when a new hour has begun the
log-file should be added to the zip archive.

/Kejpa
"Cor Ligthert" <no************ @planet.nl> wrote in message
news:uO******** ********@TK2MSF TNGP15.phx.gbl. ..
Kepja,

I have assumed from your messages that the information in both Zip files is absolute the same and that it is exactly the same kind of process that
starts in almost the same time.

Before we understand each other wrong.

Cor
"Kejpa" <kS*******@saj. fi>

"Cor Ligthert" <no************ @planet.nl> wrote in message
news:OT******** *****@TK2MSFTNG P11.phx.gbl...
Kepja,

My simple answer is catch that error and close the thread.

What am I missing with this answer?


Probably nothing. I was just not sure wheather or not that was the
best/cleanest way to do it...

/Kejpa


Nov 21 '05 #6
> Is each object running in their own thread?
Yup, each object is listening for messages and write down them to the log as
they arrive.
I would consider separating the logic that creates the zip file from the
objects themselves. Let the objects themselves simply write to the log file.
You mean I should create just one global log object and let the listeners
use that one?
Currently I'm creating a separate log object for each object, when the log
object discovers a change of hour it starts a separate thread that will zip
the log.
Alternatively you can use one or more SyncLock statements to ensure that
only a single Thread is zipping the file at a time. Primarily you want a
SyncLock around the time check to see if zipping needs to occur. I would
consider putting a separate SyncLock (on a different lock object) around the zipping itself, just to be certain. I am using synclock on the zip file (IO.FileInfo object) but it still messes
up now and then.
Hope this helps
Jay

Sure does,
At least I'm not sure I did the right thinking at first ;)

Regards
/Kejpa
Nov 21 '05 #7
Kejpa,
It sounds like each log object writes to a single log file, correct?

Each thread can have its own log object, although I normally have a single
log object (as its easier to share the padlock itself (the object that is
SyncLocked)). Either way: I am suggesting the log object does not do the
zipping.

I am suggesting creating a single zip object that based on a timer
(System.Timers. Timer or
System.Threadin g.Timer) adds the single log file to the zip file. The reason
I am suggesting this is that I expect the act of zipping takes longer then
the act of writing a log entry. The zip thread could rename the log & create
a new log allowing the other threads to keep running, then the zip thread
could save the log file to the zip file at its leisure.
I am using synclock on the zip file (IO.FileInfo object) but it still
messes
up now and then.

When you use SyncLock you need to be certain that the object that is being
locked is shared between all threads. Also you need to be certain you are
locking enough code without locking too much.

It might be helpful if you could show us your log & zipping code, that way I
or someone else may be able to see why the zipping doesn't work as you
expect.

Hope this helps
Jay

"Kejpa" <kS*******@saj. fi> wrote in message
news:cm******** **@gandalf.alco m.aland.fi...
Is each object running in their own thread?

Yup, each object is listening for messages and write down them to the log
as
they arrive.
I would consider separating the logic that creates the zip file from the
objects themselves. Let the objects themselves simply write to the log

file.
You mean I should create just one global log object and let the listeners
use that one?
Currently I'm creating a separate log object for each object, when the log
object discovers a change of hour it starts a separate thread that will
zip
the log.
Alternatively you can use one or more SyncLock statements to ensure that
only a single Thread is zipping the file at a time. Primarily you want a
SyncLock around the time check to see if zipping needs to occur. I would
consider putting a separate SyncLock (on a different lock object) around

the
zipping itself, just to be certain.

I am using synclock on the zip file (IO.FileInfo object) but it still
messes
up now and then.
Hope this helps
Jay

Sure does,
At least I'm not sure I did the right thinking at first ;)

Regards
/Kejpa

Nov 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
401
by: John Doe | last post by:
Hi all, I know the standard doesn't care about threads (wrongly :-) But in current compilers implementation, is the "list" which holds count of the occupied and free heap addresses SHARED among various threads or not? I don't know if I was clear: Case1: the list which holds count of what is free and what is occupied is SHARED among all the threads. In this case each
1
3399
by: Macca | last post by:
Hi, I have a C# Solution/Application that contain 4 projects. Each of these projects needs at some time to access the same database. I would like to know how to share a single connection between these projects as i assume this would be more efficient than having a separate connection string for each project.
0
1293
by: Greg Roberts | last post by:
I want to be able to share a cache of data objects and their lookup dictionary among several processes on the same PC. I don't want to use IPC coms to a "cache server" but want to have near native memory speeds for access. I am familiar with approaches like http://www.codeproject.com/dotnet/globalcache.asp
6
1621
by: Tony Fonager | last post by:
I am currently developing a statistics system in ASP.NET, and need to share information about the customers websites, in this application. (I have simplified my code, to make my project easier to explain.) The simple version of the system is like this : A customer inserts HTML code on his webpage, which contacts my statistics server each time the customers website recieves a hit - like a classic "register website traffic" system. ...
8
4556
by: Tony Fonager | last post by:
I am currently developing a statistics system in ASP.NET, and need to share information about the customers websites, in this application. (I have simplified my code, to make my project easier to explain.) The simple version of the system is like this : A customer inserts HTML code on his webpage, which contacts my statistics server each time the customers website recieves a hit - like a classic "register website traffic" system. ...
6
1997
by: Gary Lee | last post by:
In VB.NET using CDO, I'd like to allow multiple threads to share a single MAPI.Session object. If I declare and instantiate sessions within each thread, I'm OK (although this negates the efficiency I'm looking to add). But when I declare, e.g., Public objSession As MAPI.Session I can't access objSession from a worker thread. Thanks in advance for any advice.
1
1901
by: Daniel | last post by:
are System.Data.SqlClient.SqlConnection thread safe? can many threads share a System.Data.SqlClient.SqlConnection instance without any synchronization?
5
12247
by: Tony Gravagno | last post by:
I have a class that instantiates two Timer objects that fire at different intervals. My class can be instantiated within a Windows Form or from a Windows Service. Actions performed by one of the event handlers may take longer than the interval for either of the timers, so it's possible for multiple events to fire "simultaneously" and for events to queue up. I'm attempting to get the timers to sync on some reference type object, or use...
6
2180
by: Immortal Nephi | last post by:
First class is the base class. It has two data: m_Base1 and m_Base2. Second class and third class are derived classes and they are derived from first class. m_Base1 and m_Base2 are inherited into two derived classes. Second class has its own m_Base1 and m_Base2 and third class does the same. I am curious. How can second class and third class share the same m_Base1 and m_Base2? You define second class first and enter data into...
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5298
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.