By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,158 Members | 1,325 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,158 IT Pros & Developers. It's quick & easy.

Object with callback destroyed ??

P: n/a
Hello,

I have a project like that :
.....
TestClass t;
for (i=1;i<=x;i++)
{
t=new TestClass(params);
t.Save();
}
....

In the constructor of TestClass, if params has a particular value, I create
a TCPClient, connect it to a serveur, and run a (asynch) beginread.
When a read some data, I resend some other , ...
If all is good, the dialog is max 2-3 second long
My question :
Is that good ?
when I write t=new ..., I think I lost the reference to the precedent
constructed class, so what with the asynch callback? it's destructed and
never called ?

And if i'm wrong, what is the best solution to correct that ?
The for() is for example? Normaly it's data readed from a stream (serialport
or TCP/IP), and I must create class taht represent Event readed.

Thx

Mar 31 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Do you want to wait for the old instance of TestClass to complete? Then you
should use an AutoResetEvent, call WaitOne before instantiating new
TestClass, and Set after the operation is complete.
If you don't intend to wait for the operation to complete, you should keep
references to all TestClasses you've instantiated in a simple
List<TestClass>, for example.

"Geoffrey" <AE**************@dufour.be> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
Hello,

I have a project like that :
....
TestClass t;
for (i=1;i<=x;i++)
{
t=new TestClass(params);
t.Save();
}
...

In the constructor of TestClass, if params has a particular value, I
create
a TCPClient, connect it to a serveur, and run a (asynch) beginread.
When a read some data, I resend some other , ...
If all is good, the dialog is max 2-3 second long
My question :
Is that good ?
when I write t=new ..., I think I lost the reference to the precedent
constructed class, so what with the asynch callback? it's destructed and
never called ?

And if i'm wrong, what is the best solution to correct that ?
The for() is for example? Normaly it's data readed from a stream
(serialport
or TCP/IP), and I must create class taht represent Event readed.

Thx

Mar 31 '06 #2

P: n/a
No, I don't want to wait to complete.

I wan't to be sure that all the TCP/IP communicatie are good completed.
So, I think I have to keep all references or make my tcp/ip communicatie
synchronous ...

And what if in testclass, I create a class ClassCommunicatie with a function
start.
And call this function in a ThreadStart() ?

"Lebesgue" <no****@spam.jp> a écrit dans le message de
news:Oz**************@TK2MSFTNGP10.phx.gbl...
Do you want to wait for the old instance of TestClass to complete? Then you should use an AutoResetEvent, call WaitOne before instantiating new
TestClass, and Set after the operation is complete.
If you don't intend to wait for the operation to complete, you should keep
references to all TestClasses you've instantiated in a simple
List<TestClass>, for example.

"Geoffrey" <AE**************@dufour.be> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
Hello,

I have a project like that :
....
TestClass t;
for (i=1;i<=x;i++)
{
t=new TestClass(params);
t.Save();
}
...

In the constructor of TestClass, if params has a particular value, I
create
a TCPClient, connect it to a serveur, and run a (asynch) beginread.
When a read some data, I resend some other , ...
If all is good, the dialog is max 2-3 second long
My question :
Is that good ?
when I write t=new ..., I think I lost the reference to the precedent
constructed class, so what with the asynch callback? it's destructed and
never called ?

And if i'm wrong, what is the best solution to correct that ?
The for() is for example? Normaly it's data readed from a stream
(serialport
or TCP/IP), and I must create class taht represent Event readed.

Thx


Mar 31 '06 #3

P: n/a
No, I don't want to wait to complete.

I wan't to be sure that all the TCP/IP communicatie are good completed.
So, I think I have to keep all references or make my tcp/ip communicatie
synchronous ...

And what if in testclass, I create a class ClassCommunicatie with a function
start.
And call this function in a ThreadStart() ?

"Lebesgue" <no****@spam.jp> a écrit dans le message de
news:Oz**************@TK2MSFTNGP10.phx.gbl...
Do you want to wait for the old instance of TestClass to complete? Then you should use an AutoResetEvent, call WaitOne before instantiating new
TestClass, and Set after the operation is complete.
If you don't intend to wait for the operation to complete, you should keep
references to all TestClasses you've instantiated in a simple
List<TestClass>, for example.

"Geoffrey" <AE**************@dufour.be> wrote in message
news:uc**************@tk2msftngp13.phx.gbl...
Hello,

I have a project like that :
....
TestClass t;
for (i=1;i<=x;i++)
{
t=new TestClass(params);
t.Save();
}
...

In the constructor of TestClass, if params has a particular value, I
create
a TCPClient, connect it to a serveur, and run a (asynch) beginread.
When a read some data, I resend some other , ...
If all is good, the dialog is max 2-3 second long
My question :
Is that good ?
when I write t=new ..., I think I lost the reference to the precedent
constructed class, so what with the asynch callback? it's destructed and
never called ?

And if i'm wrong, what is the best solution to correct that ?
The for() is for example? Normaly it's data readed from a stream
(serialport
or TCP/IP), and I must create class taht represent Event readed.

Thx


Apr 3 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.