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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:53:02+00:00 2026-05-28T02:53:02+00:00

I am writing an asynchronous class to simplify function operation. Below is my code:

  • 0

I am writing an asynchronous class to simplify function operation. Below is my code:

using System;

namespace AsyncLibery
{
public class AsyncLibery
{
    delegate void Exec(); // No input parameter, no return value
    delegate void ExecWithParams<T>(T T1); //One input parameter, no return value
    delegate void ExecWithParams<T1, T2>(T1 t1,T2 t2); //Two input parameters, no return value 
    delegate void ExecWithParams<T1, T2, T3>(T1 t1, T2 t2, T3 t3);//Three input parameters, no return value
    delegate void ExecWithParams<T1, T2, T3, T4>(T1 t1, T2 t2, T3 t3, T4 t4);//Four input parameters,no return value

    delegate T  ExecWithReturnType<T>(); //No input parameter, one return value
    delegate T2 ExecWithReturnType<T1, T2>(T1 t1); //One input parameter, one return value
    delegate T3 ExecWithReturnType<T1, T2, T3>(T1 t1, T2 t2);//Two input parameters, one return value
    delegate T4 ExecWithReturnType<T1, T2, T3, T4>(T1 t1, T2 t2, T3 t3);//Three input parameters, one return value
    delegate T5 ExecWithReturnType<T1, T2, T3, T4, T5>(T1 t1, T2 t2, T3 t3, T4 t4);// Four input parameters, one return value.

    #region no input parameter, no return value
    public void BeginInvokeEx(Action actionFunction)
    {
        Exec exec = new Exec(actionFunction);
        exec.BeginInvoke(new AsyncCallback(EndInvokeEx), exec);
    }

    private void EndInvokeEx(IAsyncResult iar)
    {
        Exec exec = (Exec)iar.AsyncState;
        exec.EndInvoke(iar);
    }
    #endregion

    #region one input parameter, no return value
    public void BeginInvokeEx<T>(Action<T> actionFunction,T T1)
    {
        ExecWithParams<T> exec = new ExecWithParams<T>(actionFunction);
        exec.BeginInvoke(T1, new AsyncCallback(EndInvokeEx1), exec);
    }

    private void EndInvokeEx1(IAsyncResult iar)
    {
        ExecWithParams<T> exec = (ExecWithParams<T>)iar.AsyncState;
        exec.EndInvoke(iar);
    }
    #endregion
}
}

When I complied the code, it throws me an exception like “The type or namespace name ‘T’ could not be found (are you missing a using directive or an assembly reference?)”, the exception is appeared at below code :

ExecWithParams<T> exec = (ExecWithParams<T>)iar.AsyncState;

I know that we must refer T parameter the specific type like int or string or anything else.
But who can help me without modifying the T parameter? is there any good method to deal with it?
thx.

  • 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-05-28T02:53:03+00:00Added an answer on May 28, 2026 at 2:53 am

    Make EndInvokeEx1 generic:

    private void EndInvokeEx1<T>(IAsyncResult iar)
    {
        ExecWithParams<T> exec = (ExecWithParams<T>)iar.AsyncState;
        exec.EndInvoke(iar);
    }
    

    And change your BeginInvokeEx accordingly:

    public void BeginInvokeEx<T>(Action<T> actionFunction,T T1)
    {
        ExecWithParams<T> exec = new ExecWithParams<T>(actionFunction);
        exec.BeginInvoke(T1, new AsyncCallback(EndInvokeEx1<T>), exec);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asynchronous socket listener class like this: using System; using System.Collections.Generic; using
Writing an asynchronous Ping using Raw Sockets in F#, to enable parallel requests using
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
I'm in the process of writing a asynchronous-operation manager somewhat similar to the BackgroundWorker
I am writing a wrapper class for an activex control using a FireBreath plugin.
I'm writing an ASP.NET web service using C# that has a DoLookup() function. For
I'm writing a class library that will offer some asynchronous processing, and want to
I'm writing an asynchronous server and client with C#. I took sample code from
I am writing a simple application using the Facebook iPhone SDK. The Facebook code
One of the main purposes of writing code in the asynchronous programming model (more

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.