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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:37:23+00:00 2026-06-17T04:37:23+00:00

I have the following method : while (TryCount < 2) { Lock.Try<object>(inCommandObj.Connection, _timeout, delegate(DataSet

  • 0

I have the following method :

while (TryCount < 2)
{
    Lock.Try<object>(inCommandObj.Connection, _timeout, delegate(DataSet ds)
    {
        dataAdapter = new OdbcDataAdapter(inCommandObj);
        returningObj = dataAdapter.Fill(ds);
        done = true;
        return returningObj;
    });

    if (done)
        break;

    inCommandObj.Cancel();
}

You can see that Im trying to pass a DataSet in to this anonymous method but it does not like it? How can I make this possible?

Bestregards

Edit 1 : Exception message now is : Delegate ‘System.Func’ does not take 1 arguments

Edit 2 : In this case I need to fill a existing dataset with the dataAdapter.Fill method. This have to be done using a lock(with timout) becouse there will be alot of threads running this method. If the lock times out I need to cancel the current MySQL command that have frezzed and then try to send a new command(1 time).

Edit 3 : This is how the lock Class looks like :

public static class Lock
    {
        public static T Try<T>(object objLock, int timeout, Func<T> f)
        {
            if (System.Threading.Monitor.TryEnter(objLock, timeout))
            {
                try
                {
                    return f.Invoke();
                }
                finally
                {
                    System.Threading.Monitor.Exit(objLock);
                }
            }
            return default(T);
        }

        public static void Try(object objLock, int timeout, Action f)
        {
            if (System.Threading.Monitor.TryEnter(objLock, timeout))
            {
                try
                {
                    f.Invoke();
                }
                finally
                {
                    System.Threading.Monitor.Exit(objLock);
                }
            }
        }
    }
  • 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-17T04:37:24+00:00Added an answer on June 17, 2026 at 4:37 am

    In this line:

    public static T Try<T>(object objLock, int timeout, Func<T> f)
    

    Func<T> is looking for a function that takes no parameters and returns a T. You’re sending it a delegate that takes a DataSet and returns an object.

    Since you’re creating a new DataSet in your delegate anyway, just drop the DataSet ds from the delegate and you should be all set.

    In fact, you can simplify this to:

    Lock.Try<object>(inCommandObj.Connection, _timeout, () =>
    {
        var ds = new DataSet();
        dataAdapter = new OdbcDataAdapter(inCommandObj);
        returningObj = dataAdapter.Fill(ds);
        done = true;
        return returningObj;
    });
    

    If that doesn’t do what you intended, then you need to refactor Try to take a different Func argument, or consider a totally different solution.

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

Sidebar

Related Questions

I have the following method: public static T ExecuteScalar<T>( string query, SqlConnection connection, params
While using WCF and OperationContracts I have the following method defined: [OperationContract] [FaultContract(typeof(ValidationFault))] [FaultContract(typeof(FaultException<ExceptionDetail>))]
I have the following method definition which is intended to search a JSON object
How can I invoke following method while I have not TRootEntity , but have
I have a WCF service with the following method: [OperationContract] TernaryWebServiceResponse<long> ModifyObservations(...); Response object
I have the following method inside my repository class, to retrieve a Session object
Suppose i have the following method : public void runLoop(SomeIterator it){ while(it.hasNext()){ //do something
I have following method in wcf webenabled service Public Person AddPerson(Person p); As of
I have following method which I am using to load ActiveX control dynamically, Dim
I have the following method, which takes in the name of a file as

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.