Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Asynchron

Asynchron

Scheduled Pinned Locked Moved C#
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    greekius
    wrote on last edited by
    #1

    In a Page (there is no async=true tag); i call a procedure asynchrously. Sometimes it calls the callback; sometimes not. Why do i face this reason?

    private void AsynchronProcedure()
    ....
    try
    {
    dbSqlConnection.Open();

            IAsyncResult asyncResult = dbSqlCommand.BeginExecuteNonQuery(MyCallBack, dbSqlCommand);
    
        }
        catch (Exception ex)
        {
    
        }
        finally
        {
            dbSqlConnection.Close();
        }
    
    
    }
    
    private void MyCallBack(IAsyncResult asyncResult)
    {
        SqlCommand dbSqlcommand = (SqlCommand)asyncResult.AsyncState;
        try
        {
            if (asyncResult.IsCompleted)
            {
                dbSqlcommand.EndExecuteNonQuery(asyncResult);
                
            }
        }
        catch (Exception ex)
        {
    
        }
    }
    
    L 1 Reply Last reply
    0
    • G greekius

      In a Page (there is no async=true tag); i call a procedure asynchrously. Sometimes it calls the callback; sometimes not. Why do i face this reason?

      private void AsynchronProcedure()
      ....
      try
      {
      dbSqlConnection.Open();

              IAsyncResult asyncResult = dbSqlCommand.BeginExecuteNonQuery(MyCallBack, dbSqlCommand);
      
          }
          catch (Exception ex)
          {
      
          }
          finally
          {
              dbSqlConnection.Close();
          }
      
      
      }
      
      private void MyCallBack(IAsyncResult asyncResult)
      {
          SqlCommand dbSqlcommand = (SqlCommand)asyncResult.AsyncState;
          try
          {
              if (asyncResult.IsCompleted)
              {
                  dbSqlcommand.EndExecuteNonQuery(asyncResult);
                  
              }
          }
          catch (Exception ex)
          {
      
          }
      }
      
      L Offline
      L Offline
      leppie
      wrote on last edited by
      #2

      greekius wrote:

      In a Page (there is no async=true tag); i call a procedure asynchrously.

      Two different things. The former for for page handling. The latter is you. Neither has an effect on each other.

      greekius wrote:

      Sometimes it calls the callback; sometimes not. Why do i face this reason?

      Your code is wrong. You should close the connection after the callback returns, not before it (as you are doing now, not really, it depends, but the fact is the connection can and likely will be closed before the async call can complete).

      xacc.ide - now with TabsToSpaces support
      IronScheme - 1.0 alpha 4a out now (29 May 2008)

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups