Developer forum

Forum » Development » Notification runs twice,

Notification runs twice,


Reply

Hi guys,

 

I made a simple notification  subscriber that listenes to the Order.Steps.Completed event.

 

My problem is that the event is run twice when i complete an order.

 

My code looks like this:

 

public class budgetMaxOrderStepsCompleted : Dynamicweb.Extensibility.NotificationSubscriber{
 public override void OnNotify( string notification, object[] args ) {
  SaveSomething();
 }
}

 

The function SaveSomething() saves the OrderID to the database, and i can se that 2 records are saved on each order completion.

 

I testet it on my local machine, and i only ran once, now that it's live these double posts occur.

 

as far as i can see both my local and the live solution use the same version of DW.

 


Replies

 
Reply

If both the cart and the custom code saves a record, two records will be saved. Have you tried performing an action that the standard method doesn't already do, like writing something to a file:

 

Base.WriteTextFile(System.Web.HttpContext.Current.Server.MapPath("/Files/Filer/Doublecheck.txt"), "Check", true);

 

If there are two lines after running the notification subscriber once, we may have a problem.

 
Reply
Sorensen wrote:

If both the cart and the custom code saves a record, two records will be saved. Have you tried performing an action that the standard method doesn't already do, like writing something to a file:

 

Base.WriteTextFile(System.Web.HttpContext.Current.Server.MapPath("/Files/Filer/Doublecheck.txt"), "Check", true);

 

If there are two lines after running the notification subscriber once, we may have a problem.

Hi Lars,
 

 

I tried to write a line to a file on each order completion, and now i can't recreate the error, only one line is written to the file, and my SaveSomething() is only called once aswell

 I didn't change anything except adding these lines:

StreamWriter s = new StreamWriter( HttpContext.Current.Server.MapPath( "/Files" ) + @"\Filer\Doublecheck.txt", true );
s.WriteLine( "Check" );
s.Close();
s.Dispose();

 

Kinda weird. 

 

If the problem returns i'll come back here :)

 

 

 
Reply

Ok, but please keep an eye out for this. Earlier we've experienced addons being loaded more than once, but when you dump a new assembly into the bin directory, everything is flushed and loaded agaiun. So if there in fact was an error in relation to this, it might occur again.

 
Nicolai Høeg Pedersen
Reply

It very much sounds like the loading twice bug.

 

We actually committed code today to accomodate this...

 
Reply

I'll keep an eye out.

I've experienced the "run twice or more" bug before, so i know there's a solution.

 

You must be logged in to post in the forum