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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:07:00+00:00 2026-06-15T10:07:00+00:00

I have a simple heartbeat method for my DB2/400: public bool CheckConnection() { try

  • 0

I have a simple heartbeat method for my DB2/400:

public bool CheckConnection()
        {
            try
            {
                using (OleDbConnection db = new OleDbConnection( this.conString ))
                {
                    OleDbCommand cmd = new OleDbCommand();
                    cmd.CommandText = "select 1 from sysibm.sysdummy1";
                    cmd.Connection = db;
                    db.Open();
                    cmd.ExecuteReader();
                    db.Close();
                    return true;
                }
            }
            catch (Exception)
            {
                return false;
            }
        }

I want to use this when my application runs ,and of course i dont want to hold the execution of the rest of the form.

My main method in my form:

public FrmMain()
    {
        InitializeComponent();
        PrepareFormTexts();
        PrepareFormData();
        PrepareStateClass();
        CheckDbConnection();
        //Initialize Data Access for AS400
        Dal = JDE8Dal.Instance;
        Dal.conString = Properties.Settings.Default.conAS400;
        //Initialize Icons
        picCon.Image = Properties.Resources.ledGreen;
        picStatus.Image = Properties.Resources.ledGreen;
        // Load recording from file if they exist
        PrepareRecordings(AppState.DataFileName,'|');
    }

CheckDbConnection method:

    private async Task<bool> CheckDbConnection()
    {
        return await Task.Factory .StartNew(() => Dal.CheckConnection());
    }

I think it runs fine but i get a warning

Warning 1 Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the ‘await’ operator to the result of the call.

Should i ignore it? should i put async in main method?

UPDATE: After discussing below i found out that since i am using async package for .NET 4.0 i cant really make my dal methods non-blocking. the only thing i can do is to use the async/await + task.factory.startnew in order to keep my app working while dal works on the background.

Code below:

public FrmMain()
    {
        InitializeComponent();
        Load += FormLoadInit;
    }

    private async void FormLoadInit(object sender, EventArgs e)
    {
        PrepareFormTexts();
        PrepareFormData();
        PrepareStateClass();
        txtLot.Select();
        //Initialize Data Access for AS400
        Dal = JDE8Dal.Instance;
        Dal.conString = Properties.Settings.Default.conAS400;
        // Load recording from file if they exist
        PrepareRecordings(AppState.DataFileName, '|');
        bool cn = await Task.Factory.StartNew(() => Dal.CheckConnection());
        //Initialize Icons
        picCon.Image = cn ? Resources.ledGreen : Resources.ledRed;
        picStatus.Image = Properties.Resources.ledGreen;

    }
  • 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-15T10:07:02+00:00Added an answer on June 15, 2026 at 10:07 am

    What the warning is telling you is that you are effectively firing and then forgetting this asynchronous task. You never actually use the results of the operation, nor do you even store the Task itself to allow any future code to rely on it’s result (or even knowing when it finished).

    This won’t break anything, but it’s not really helpful either. You may as well just not call the method. Now, in your case this is just a dummy list, so you need to ask yourself what you’re trying to test. Do you want to display some dummy value on the form just as a proof of concept? If so, you’re code will need a few changes to get there.

    To actually use the results of the query you’ll need to await it, and you can’t do that from within a constructor. You’ll want to move the code to the Form Load event handler and mark the handler as async so that you can await within it.

    Another issue you have is that, to create your async method, you’re starting a new task that will run in a thread pool and then having it perform blocking methods. The primary advantage of using the async/await model is that you don’t need to do that. You should be using database querying methods that directly give you a Task<T> as their return value and don’t block. You can then await on those tasks (or just return them) such that your application has no threads being blocked while you wait.

    Your CheckConnection method should look something like this:

    public async Task<bool> CheckConnection()
    {
        try
        {
            using (OleDbConnection db = new OleDbConnection(this.conString))
            {
                OleDbCommand cmd = new OleDbCommand();
                cmd.CommandText = "select 1 from sysibm.sysdummy1";
                cmd.Connection = db;
                db.Open();
                await cmd.ExecuteReaderAsync();
                return true;
            }
        }
        catch (Exception)
        {
            return false;
        }
    }
    

    CheckDbConnection then doesn’t need to exist. There’s no need to wrap CheckConnection in a Task because it already returns a task.

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

Sidebar

Related Questions

I have simple method in C# : public static string BetweenOf(string ActualStr, string StrFirst,
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have simple problem: class Weapon{ public: int dmg; float speed; int rate; };
I have simple example: function File(name) { this.name = name this.text = null }
I have simple jQuery Mobile site created using asp.net mvc 2 and uses basic
i have simple side menu with this html code : <div id=menu> <div> Menu
I have simple models with generic relations from this example at the Django Project
I have simple query, but when I'm trying to execute this query I'm getting
I have simple application when I need to stop a background thread using Stop()
I have simple win32 application (not dialog box), and treeview in this application. All

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.