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

  • SEARCH
  • Home
  • 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 8693273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:30:49+00:00 2026-06-13T00:30:49+00:00

In synchronous model it’s simply using (MyServiceClient msc = new MyServiceClient()) { msc.Method(); }

  • 0

In synchronous model it’s simply

using (MyServiceClient msc = new MyServiceClient())
{
   msc.Method();
}

but if I must wait to end of this method, and then do something, it can’t work

private void EventHandler<MethodCompletedEventArgs> myEventHandler = new EventHandler<MethodCompletedEventArgs>(methodBody);

using (MyServiceClient msc = new MyServiceClient())
{
   msc.MethdCompleted += myEventHandler;
   msc.BeginMethod();
}

private void MethodBody()
{
//exception: client state is aborted
}

Also how to call async mehod in using statement?

  • 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-13T00:30:50+00:00Added an answer on June 13, 2026 at 12:30 am

    You can store a reference to your service client and manually invoke its Dispose method once the event calls back. You just have to do some extra work managing exceptions and generally ensuring that Dispose is called eventually. Also watch for conditions where you might create/overwrite multiple instances of msc while waiting for an old one to complete:

    One way to make sure that you don’t dispose the wrong instance if you execute the same code multiple times is to use a local lambda/anonymous function:

    MyServiceClient msc = new MyServiceClient();
    
    msc.MethdCompleted += (sender, args) => 
    {
        try
        {
            myEventHandler(sender, args);
        }
        finally
        {
            msc.Dispose();
        }
    };
    
    msc.BeginMethod();
    

    It might get a bit messier than that; if an exception is thrown on msc.BeginMethod() you should catch that as well and call Dispose most likely (but you don’t want to call Dispose more than once)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to model a asynchronous job processing framework using MailboxProcessor. My requirements are
I've been using synchronous XMLHttpRequest with responseType set to arraybuffer for quite a while
I'm using super-simple synchronous C# Sockets for an assignment. The assignment is to create
I was trying to understand the terms Synchronous and Asynchronous communication but i am
I'm trying to read a text file using a synchronous request. It doesn't work
I am calling a library method that is synchronous. I'd like to use the
I'm developing an Asynchronous Game Server using .Net Socket Asynchronous Model( BeginAccept/EndAccept...etc.) The problem
Providing Synchronous and Asynchronous versions of Method in c# asks how to provide an
I am using JOliver's EventStore and for now I am using a synchronous dispatcher
I am learning asynchronous programming using C# and I usually use BeginInvoke , but

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.