473,407 Members | 2,629 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Calling methods from constructor?

Hi,

I have a class whose constructor accepts a Socket as an argument. The
constructor then makes a call to Socket.BeginReceive(). The callback
delegate passed to BeginReceive() is a method of my class. There is a slight
chance that the callback delegate will be called from the I/O thread pool
BEFORE my constructor completes. Is calling this delegate before the
constructor finishes a problem?

In C++, this type of arrangement was a problem as I recall. In C#, it
doesn't seem like it SHOULD be a problem. After all, I can call private
methods from my constructor so why shouldn't some external party be able to
call them in the midst of construction as well? In any case, I just wanted
to double-check!

Granny
Jul 19 '05 #1
2 1875
To side-step this issue and possible others, you could (of course) create
..Send() public method or .Connect() and use that after construction. You
can still set the socket var in your constructor and/or property of the
class.
--wjs
"Grandma Wilkerson" <tu**@bottleneck.scalability.crash.dum> wrote in message
news:OW**************@TK2MSFTNGP12.phx.gbl...
Hi,

I have a class whose constructor accepts a Socket as an argument. The
constructor then makes a call to Socket.BeginReceive(). The callback
delegate passed to BeginReceive() is a method of my class. There is a slight chance that the callback delegate will be called from the I/O thread pool
BEFORE my constructor completes. Is calling this delegate before the
constructor finishes a problem?

In C++, this type of arrangement was a problem as I recall. In C#, it
doesn't seem like it SHOULD be a problem. After all, I can call private
methods from my constructor so why shouldn't some external party be able to call them in the midst of construction as well? In any case, I just wanted
to double-check!

Granny

Jul 19 '05 #2
Grandma Wilkerson <tu**@bottleneck.scalability.crash.dum> wrote:
I have a class whose constructor accepts a Socket as an argument. The
constructor then makes a call to Socket.BeginReceive(). The callback
delegate passed to BeginReceive() is a method of my class. There is a slight
chance that the callback delegate will be called from the I/O thread pool
BEFORE my constructor completes. Is calling this delegate before the
constructor finishes a problem?


Well, it'll be a potential problem if the delegate relies on
information which is set up after Socket.BeginReceive() is called, but
I don't think it's fundamentally a problem. Probably worth documenting
very clearly though, for maintenance purposes.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Jul 19 '05 #3

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

Similar topics

3
by: Christian Dieterich | last post by:
Hi, I need to create many instances of a class D that inherits from a class B. Since the constructor of B is expensive I'd like to execute it only if it's really unavoidable. Below is an example...
4
by: Jerry Krinock | last post by:
I've written the following demo to help me understand a problem I'm having in a larger program. The "main" function constructs a Foo object, and then later "reconstructs" it by calling the...
2
by: Grandma Wilkerson | last post by:
Hi, I have a class whose constructor accepts a Socket as an argument. The constructor then makes a call to Socket.BeginReceive(). The callback delegate passed to BeginReceive() is a method of my...
8
by: Greg Bacchus | last post by:
I have a base class with a method that is to be called in the constructor of the inheritting classes. Is there any way of determining, say, the Type of the class that is calling it. e.g. ...
5
by: Pete Davis | last post by:
I know I can use reflection to call internal, protected, and private methods in a class, but I need to instantiate an object that is public but has an internal constructor (The CurrencyManager...
12
by: torbs | last post by:
Hi I have a a function with several methods. For simplicity it looks a bit like this: super.prototype.aProperty="HELLO"; super.prototype.returnValue = function () { return 2;
3
by: rickeringill | last post by:
Hi comp.lang.javascript, I'm throwing this in for discussion. First up I don't claim to be any sort of authority on the ecmascript language spec - in fact I'm a relative newb to these more...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
5
by: bizt | last post by:
Hi, Below I have a simple object / function thing (still getting head round these) declaration: function MyObject() { this.alertMe = function() { alert('hello'); }; this.alertMeAgain() {
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.