Calling Custom DLL in AC ASCX.CS Pages
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: Calling Custom DLL in AC ASCX.CS Pages
Hehe
I prefer the days when I get the bear. But then again, don't we all?
I prefer the days when I get the bear. But then again, don't we all?
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: Calling Custom DLL in AC ASCX.CS Pages
Say, I was wondering...
Is there also a way to code the function in the ASCX.CS file that calls the DLL so that it will call the function and move on as soon as it makes the call? It can take a little time for the DLL to communicate with the NetSuite servers (due to their functionality, based on every other integration I've done). I would like it to be able to call the function and then move on so that the little "Processing" window isn't sitting there every time a customer places an order. I guess this would be an asynchornous call, but I can't do it in the DLL as there is a restriction of a maximum of twenty asynchronous web services calls per month. I was hoing there was a way to do it outside the DLL.
Is there also a way to code the function in the ASCX.CS file that calls the DLL so that it will call the function and move on as soon as it makes the call? It can take a little time for the DLL to communicate with the NetSuite servers (due to their functionality, based on every other integration I've done). I would like it to be able to call the function and then move on so that the little "Processing" window isn't sitting there every time a customer places an order. I guess this would be an asynchornous call, but I can't do it in the DLL as there is a restriction of a maximum of twenty asynchronous web services calls per month. I was hoing there was a way to do it outside the DLL.
Re: Calling Custom DLL in AC ASCX.CS Pages
Who's limit is that? I've never heard of such a thing.vashts1980 wrote:but I can't do it in the DLL as there is a restriction of a maximum of twenty asynchronous web services calls per month.
You might try using System.Threading to make the call in a separate thread with a callback method to handle the response. That way your page processing continues at normal speed but you can still process any responses from NetSuite.
Might force you to redesign your code a bit, but in the long run it'll work much smoother.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: Calling Custom DLL in AC ASCX.CS Pages
This is actually a restriction on the system that I'm connecting AbleCommerce with, so unless you're familiar with NetSuite's web services, I'm not surprised you're unfamiliar with it.vashts1980 wrote:but I can't do it in the DLL as there is a restriction of a maximum of twenty asynchronous web services calls per month
Do you have any good resources I could look at for using System.Threading? And where would I implement it? In the ASCX.CS file or in the DLL?
Re: Calling Custom DLL in AC ASCX.CS Pages
Here's the Microsoft explanation on it:
http://msdn.microsoft.com/en-us/library ... hread.aspx
Scroll most of the way to the bottom, there's a code sample that's pretty easy to follow.
Threads are useful but they need to be done a certain way in AC7 installations. Here's a quick example:
Assume you have a 'GO' button on the page and it's purpose is to launch an update process. You don't want the update process to timeout the page because it takes a while to run.
Make sure to have this at the top with your other includes:
This is the example code:
Always best to encapsulate your code in the thread routine with a try-catch, that way you can catch problems and log them accordingly. Makes debugging it a lot easier. In fact, I write and debug the code without threading first....just easier that way. Once I've got it the way I want, I split it back up using the above design.
Remember threads in AC7 have to init the store context, otherwise the new thread has no knowledge of the current storefront.
http://msdn.microsoft.com/en-us/library ... hread.aspx
Scroll most of the way to the bottom, there's a code sample that's pretty easy to follow.
Threads are useful but they need to be done a certain way in AC7 installations. Here's a quick example:
Assume you have a 'GO' button on the page and it's purpose is to launch an update process. You don't want the update process to timeout the page because it takes a while to run.
Make sure to have this at the top with your other includes:
Code: Select all
using System.Threading;
Code: Select all
protected void MyGoButton_Click(object sender, EventArgs e)
{
System.Threading.ThreadPool.QueueUserWorkItem(MyThreadRoutine);
}
private static void MyThreadRoutine(object state)
{
Store _Store = StoreDataSource.Load(1);
Token.Instance.InitStoreContext(_Store);
... your code continues from here...
}
Remember threads in AC7 have to init the store context, otherwise the new thread has no knowledge of the current storefront.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: Calling Custom DLL in AC ASCX.CS Pages
Ok, so if I was going to add this onto the checkout page where I'm capturing newly submitting orders, then this code:
Would be added to the existing "CheckedOut()" method, and the code that I've added to that method to do what I need, the additional lines to init the store context, would instead be moved to the new method I've created and referenced in the thread call, which would be "MyThreadRoutine()" in this particular example.
Does that sound like I have it right?
Code: Select all
System.Threading.ThreadPool.QueueUserWorkItem(MyThreadRoutine);
Does that sound like I have it right?
Re: Calling Custom DLL in AC ASCX.CS Pages
yup
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: Calling Custom DLL in AC ASCX.CS Pages
Ok...
I did some extra research into threading, and this is what I've come up with. I've noticed that the majority of examples revolve around methods that operate without use of any parameters, but I needed parameters, so I'm thinking this should work based off of what I've found so far:
I did some extra research into threading, and this is what I've come up with. I've noticed that the majority of examples revolve around methods that operate without use of any parameters, but I needed parameters, so I'm thinking this should work based off of what I've found so far:
Code: Select all
int newOrderId = response.OrderId;
Order newOrder = OrderDataSource.Load(newOrderId);
System.Threading.ThreadPool.QueueUserWorkItem( () => PassNewOrder(newOrder, currentUser, GetShippingAddress() ) );
-
- Lieutenant Commander (LCDR)
- Posts: 98
- Joined: Fri Apr 29, 2011 2:56 pm
Re: Calling Custom DLL in AC ASCX.CS Pages
Joe, thnks for the insight on this. I have threading implemented and it appears to be working wonderfully.