Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Async actions using same functions 1

Status
Not open for further replies.

ecucurella

Programmer
Feb 17, 2003
34
ES

Hi,

I have found a curious problem working with asyncronous call of methods !!

I will try to explain you:

- I have a class(Grib) that implements a function(GetNearData) that read some information(temperature data) in some positions in a file(from Latitude/Longitude).

- How I have to do too many read from so many files I have done 20 objects at the same time doing work and calling it trough the IAsyncResult interface

- The call to this method return by ref the data required

- The surprise was that if two objects use the same method to retrieve diferent data of the same file at the same time !! >> data returned was the same !!

There is any way to protect this error to be produced?

Thanks in advance,

cucu




 
Hi,

you could try setting a boolean variable like "FileAvailable" then only read from it if "True", Set it to False just before starting reading it and back to True when you've finished reading it.
 

Hi,

Ok, this is a good solution but it could be possible that both objects looks at this variable and see that FileAvaliable=True then both set it to False and start the reading atr same time with same problem?

Who assures me that this will not happens?

I was searching another solution more polite if it exist, anyone knows it?

Thank you,
 

ok, I'm looking at synclock and seams to be what i was looking for !!

Thank you

cucu :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top