Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8286285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:41:37+00:00 2026-06-08T11:41:37+00:00

i have some code in an object constructor similar to delegate DataSet MyInvoker; public

  • 0

i have some code in an object constructor similar to

delegate DataSet MyInvoker;

public MyObject(Param1 p1)
{
    // property sets here
    // ...

    BeginMyAsyncMethod();
}

public void BeginMyAsyncMethod() 
{
    // set some properties
    // ...

    MyInvoker inv = new MyInvoker(SomeBeginMethod);
    inv.BeginInvoke(new AsyncCallback(SomeEndMethod), null);
}

My questions are:

  1. Is this generally considered bad practice?
  2. Would it be better (or good) practice to define a start method in my class which the user would call to carry out the async action?

This answer gives me the impression that leaving it to the user is bad practice although I am talking specifically about starting async methods in the constructor, not about the correct construction of an object.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T11:41:38+00:00Added an answer on June 8, 2026 at 11:41 am

    This is easily accomplished with a slightly different approach. In all reality, this happens all the time, doesn’t it? Here’s a simple solution to give you an option without doing something dumb:

    public class MyResource
    {
        // do this instead of a constructor
        public async Task<MyResource> StartAsync()
        {
            await Task.Delay(1);
            return this;
        }
    }
    
    public class MyControl
    {
        public MyResource Resource { get; set; }
        async void Button_Click(object s, EventArgs e)
        {
            // call start as if it is a constructor
            this.Resource = await new MyResource().StartAsync();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code where I use a thread static object in C#. [ThreadStatic]
I have some code in my project that saves an object to the database,
I have some code, which uses the ExecuteStmt method on the Axapta Object when
I have written some code that loads an XML document using an XmlDocument object
I have created some python code which creates an object in a loop, and
I have some object that is instantiated in code behind, for instance, the XAML
Some code that I don't have control over is overriding the global JSON object
I have an object with the following properties GID ID Code Name Some of
I have some code that performs a deep copy using Object.clone, but I'm trying
I have asked similar questions before but here is a full demo example code.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.