.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Sharon Maxwell
Post New Web Links

Exception during asynchronous processing.

Posted By:      Posted Date: October 01, 2010    Points: 0   Category :.NET Framework
 

I have a pattern like:

          FunctionDelegatge function = new FunctionDelegatge (MyFunction);

          function.BeginInvoke(arg1, arg2, arg3, new AsyncCallback((far) =>

          {

           if (far.IsCompleted)

           {

            lock (resultLock) result.Add(function.EndInvoke(far));

            Interlocked.Decrement(ref orderCount);

           }

          }), null);



Right now every once and a while I get an exception that simply states 'A severe error occured'. In order to track down this error I was wondering if I could get some help in understanding what happens to an exception during asyncronous processing. Specifically what happens if an exception is raised in 'MyFunction' above? How can I safely catch this exception and still have the exception information available for the asynchronous delegate? Ideally I would like to have status something like the BackgroundWorker class where in the process complete method one can test a property to see if an error occurred. Also what if arg1 etc. was a SqlConnection that if the connection is terminated (this is within a WCF web service)


View Complete Post


More Related Resource Links

CLR Inside Out: Unhandled Exception Processing In The CLR

  

In this installment of CLR Inside Out Gaurav Khanna explains everything you need to know about unhandled exception processing in the .NET Framework.

Gaurav Khanna

MSDN Magazine September 2008


.NET Matters: Asynchronous Stream Processing

  

This month Stephen Toub discusses asynchronous stream processing.

Stephen Toub

MSDN Magazine March 2008


Making asynchronous calls to web services during ASP.NET page processing

  
Some ASP.NET web applications use web services to get some data that they display to users. Some pages may lay hardly on web services and these pages need some optimization to work better. In this posting I will show you how to use web services behind your ASP.NET page asynchronously and perform a lot of queries to web services. Sample code included! Eneta.Examples.WebAppThreading.zip VS2008 solution | 60KB Asynchronous page processing As an introduction let's see how ASP.NET supports asynchronous calls behind pages. Although we can use our own threading mechanism and avoid what is offered by ASP.NET it is more safe and time saving to use ASP.NET own infrastructure. The image on right that I stole from MSDN article Asynchronous Pages in ASP.NET 2.0 shows you how synchronous and asynchronous pages are processed by ASP.NET. I recommend to read this MSDN article because you can find also other methods for asynchronous calls. I will introduce you how to use PageAsyncTask based calls. If you look at diagram on right you can see that asynchronous processing of registered tasks happens between PreRender and PreRenderComplete events in separate threads. If we have data bound controls on our page we have to move data binding to PreRenderComplete event because this is the closest phase of page processing where asynchronous calls are finished.

Do ASP.NET Crystal Reports support asynchronous processing

  
CR reports take too much of processing time for our web app. I have modified the process to generate reports in the background using ASP.NET asynchronus pages concept. But now, the reports do NOT render at all. This makes me wonder whether they support background processing at all.CR reports take too much of processing time for our web app. I have modified the process to generate reports in the background using ASP.NET asynchronus pages concept.But now, the reports do NOT render at all. This makes me wonder whether they support background processing at all.

Asynchronous ASP.NET Page Processing in Layered Architecture

  

I am working on an application which involves payment gateways. Payment gateway takes some 4-5 seconds to respond. To tune the application I thought of using PageAsyncTask whenever Payments are processed.

My application uses multiple layers, for e.g before hitting to payment gateway, all sorts of calculations(taxes and all) are calculated in bussiness layer and then the payment gateway processing is done in the data access layer. Method which performs the Payments  also returns some custom message to top layers based on the response value. This is done by setting a property in the DAL class.

Now issue is how to register BeginEventHandler and EndEventHandler. I tried creating a sample application for this. But when I debugged my EndEventHandler was not getting called at all.

Sample Scenario..

On a button click event I am trying to call a DAL method which will create a HttpWebRequest and will return the response to me in a string variable

My Page Class has Events below:

protected void btnSubmit_Click(object sender, EventArgs e)
        {
            
            PageAsyncTask task = new PageAsyncTask(new BeginEventHandler(BeginAsyncOperation), new EndEventHandler(EndAsyncOperation),new EndEventHandler(TimeoutAsyncOperation), "" );
            RegisterAsyncTask(task);

Asynchronous ASP.NET Page Processing(PageAsyncTask) in Layered Architecture

  

I am working on an application which involves payment gateways. Payment gateway takes some 4-5 seconds to respond. To tune the application I thought of using PageAsyncTask whenever Payments are processed.

My application uses multiple layers, for e.g before hitting to payment gateway, all sorts of calculations(taxes and all) are calculated in bussiness layer and then the payment gateway processing is done in the data access layer. Method which performs the Payments  also returns some custom message to top layers based on the response value. This is done by setting a property in the DAL class.

Now issue is how to register BeginEventHandler and EndEventHandler. I tried creating a sample application for this. But when I debugged my EndEventHandler was not getting called at all.

Sample Scenario..

On a button click event I am trying to call a DAL method which will create a HttpWebRequest and will return the response to me in a string variable

My Page Class has Events below:

protected void btnSubmit_Click(object sender, EventArgs e)
        {
            
            PageAsyncTask task = new PageAsyncTask(new BeginEventHandler(BeginAsyncOperation), new EndEventHandler(EndAsyncOperation),new EndEventHandler(TimeoutAsyncOperation), "" );
            RegisterAsyncTask(t

When processing files recursively, why the top DirectoryInfo always throw a Exception?

  

hi

I have quite a simple app, which modify the CreationTime property of all the subfiles and subfolders in a folder, the code is like:

    void Mod(DirectoryInfo dir, DateTime time)
    {
      foreach (DirectoryInfo subDir in dir.GetDirectories())
        Mod(subDir, time);
      foreach (FileInfo fi in dir.GetFiles())
      {
        fi.CreationTime = time;
      }
      dir.CreationTime = time;
    }

I call this method with a folder like: C:\a\b, then all the subfiles and subfolders are correctly modified, but WHY I received an Exception: The process cannot access the file 'C:\a\b' because it is being used by another process.

I changed the folder to: C:\a, then C:\a\b was modified successfully, then I got an Exception:The process cannot access the file 'C:\a' because it is being used by another process.

thanks in advance.


An error occured during local report processing. Exception of type 'System.OutOfMemoryException' W

  

I've been getting this error, randomly when previewing two reports.

It does not seem to be based on report complexity, size, subreports etc. When
reports are deployed to server, they all run fine. I just get the out of memory error locally.

1. I have one version with 2 datasets, and a number of matrix, table and list data regions.
2. I have a second version with only one table data region.
3. There is no custom code, variables, prompts or generally anything other than basic
formatting in the report.
4. Both reports are based on the same SQL table.

I can seem to run the two reports (both based on same SQL table) a few times, and
then they start giving the out of memory error.

I can open other other reports and they preview fine locally.

What I've tried so far to no avail:

1. Deleted the downloaded data before refreshing the two reports.
2. Tried building the two reports before running.
3. Tried changing the process priority to high for devenv.exe.
4. Removed filters in the reports.
5. Changed the physical order of the underlying table.
6. Closed the reports and then re-opened them.
7. Close Visual Studio and Re-Open. This seems to work for a while and then the two
reports start giving the error messages again.
8. Cop

jQuery $(document).ready() and ASP.NET Ajax asynchronous postback

  
Many call it the ASP.NET jQuery postback problem, but using the technique below should make it no problem anymore. $(document).ready() isn't called after an asynchronous postback. What this means? You lose the functionality that should be executed within $(document).ready() after an UpdatePanel rendered its contents after an asynchronous postback.

jQuery live() and ASP.NET Ajax asynchronous postback

  
The issue is that normally $(document).ready() is called when the DOM is ready to be manipulated. But this doens't happen after an ASP.NET Ajax asynch postback occurs.

This means that the initial jQuery bindings won't be automatically available after the asynchronous postback is over. I underline "automatically" here because my last post describes more possibilities, how this issue can be worked around.

EXCEPTION HANDLING IN C#

  
Every self-respected programmer should include exception handling techniques. Sometimes your application will generate an error. Regardless of who was responsible for this error, the programmer or the user, it is up to the first to include the necessary exception handling techniques to keep his/her program from crashing. The .Net environment provides useful techniques for avoiding disastrous errors such as try-catch statements and user-defined exceptions.

Global Exception Handling with ASP.NET

  
After your global exception handler has done its work, you'll want to redirect the users of your website to a friendly page that tells them that something has gone wrong, and then provide them with customer support information as well as a link back to your web application's home page.

SQL Server 2005 Try and Catch Exception Handling

  
I'm pretty excited to see that there is some real error handling for T-SQL code in SQL Server 2005. It's pretty painful to have your wonderfully architected .NET solution tainted by less-than-VBScript error handling for stored procedures in the database. The big difference being the addition of TRY..CATCH blocks. Let's take a look:

how to impose javascript event processing?

  

If I have some form control like textbox and I want the event handler to be located in the html instead of at the server side, how to do that? Of course I can copy paste javascript code in the aspx file. But is it possible to do that using some object oriented approach (ie programmatically in the code behind)?

Thanks


reader.getordinal("column_may_not_exist") how to catch the exception?

  

hi,

would any body please help me to catch the exception if the column doesnot exist as my table columns are not static.

sometimes its throwing me indexoutofrange exception as the column doesnot exist

thanks for the help guys


Error while using exception handling block el 4.1

  

Hi Folks,

 

i am trying to use tyhe exception handling block of Enterprise library 4.1.

 

I just createda polisy and used IndexOutOfRangeException and added a replace handler and a logging handler to it.

I am using the NotifyRethrow PostHandlingAction to the exception.

 

During runtime I am getting an exception on the HandleException event, The exception is added below:

 

 

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 42:             catch (Exception ex)
Line 43:             {
Line 44:                 bool reThrow = ExceptionPolicy.HandleException(ex, "ReplacePolicy");
Line 45:         

userprincipal.changepassword throws exception

  

Hi all,

      userprincipal.changepassword(oldpassword, newpassword);

gives error: that is Configuration information could not be read from the domain controller, either because the machine is unavailable, or access has been denied. (Exception from HRESULT: 0x80070547)

but userDirectoryEntry.invoke("ChangePassword", new object[] { oldpassword, newpassword });

      userDirectoryEntry.CommitChanges works fine.

Any one please tell me the reason behind this.




Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend