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 161183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:10:05+00:00 2026-05-11T11:10:05+00:00

I have the following code: delegate int doStuffDel(int instanceNo, int sleepTime, int repeatCount); string

  • 0

I have the following code:

    delegate int doStuffDel(int instanceNo, int sleepTime, int repeatCount);     string result;      private int doStuff(int instanceNo, int sleepTime, int repeatCount)     {         for (int i = 0; i < repeatCount; i++)         {             Console.Write(instanceNo);             Thread.Sleep(sleepTime);         }         result = instanceNo + ' repeated ' + repeatCount;         return instanceNo;     }      private void button3_Click(object sender, EventArgs e)     {         doStuffDel del = doStuff;         IAsyncResult ar = del.BeginInvoke(3, 120, 50, finishedCallback, result);     }      private void finishedCallback(IAsyncResult ar)     {         Console.WriteLine('Done. The result was ' + ar.AsyncState.ToString());     } 

I thought the res.AsyncState would return the string, passed as the last argument in the call to BeginInvoke, but it’s null. Does anybody know why?

PS, I know I could pass the del as the last argument in BeginInvoke and then call EndInvoke in the callback, to get some result from the doStuff method, — or I could just get the string val from the class! — but I am surpised that the AsyncState on the AsyncResult object is null…

  • 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. 2026-05-11T11:10:05+00:00Added an answer on May 11, 2026 at 11:10 am

    The value of ar.AsyncState is the value of result when you originally pass it to BeginInvoke. The fact that when you passed it, you used the value of result doesn’t mean that it’s ‘bound’ to the result variable. It’s just the value of the result variable when you pass it to start with.

    To see this, either set result to some test value before calling BeginInvoke, or just pass a string literal instead. Either way, you’ll get that value in the callback.

    On the other hand, your callback and original delegate both have the same target object, so you could use use result within the callback and it would have the value you want – that’s another way of maintaining state.

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

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try awk -F"_" -f <file> '{ print $1" "$2" "$3"_"$4… May 12, 2026 at 12:51 am
  • Editorial Team
    Editorial Team added an answer Seems to be something they're working on as we speak.… May 12, 2026 at 12:51 am
  • Editorial Team
    Editorial Team added an answer There are characters other than line-breaks which will cause you… May 12, 2026 at 12:51 am

Related Questions

I have the following code (calling a method returning IEnumerable): FibonacciWithLinq.Skip(delegate() { return 5;
I am trying to understand the meaning and use of the param parameter in
Consider the following main() method which you would find most iPhone applications: int main(int
I have a sequence of functions that look very similar but for a single

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.