Josh Lane on .NET RSS 2.0
 Tuesday, January 23, 2007

I'm still mucking around with ASP.NET AJAX (get your 1.0 RTM bits here, y'all) and I needed a client-side "progressbar"-type thingie to display during AJAX postbacks. Note that I don't care much about "10% done... 20% done...", etc. I just wanted to give the user some visual indication that something's happening behind the scenes (especially since the entire page isn't visibly refreshing itself... this being the whole point of UpdatePanel and friends in the first place).

There are bazillions of Javascript progressbar implementations out there, but I wanted one that simply ping-pongs back and forth forever... that way you can show/hide it as needed in client-side code, to indicate background work of some sort.

I stumbled on Sahil Malik's implementation, which wasn't quite what I wanted, but close. He wrote a custom WebControl that allows you to specify percent complete and all that... so I modified it to do what I wanted instead.

For those who may not know, custom WebControls give you complete, well, control over their rendered output... so not only does the control emit the necessary HTML (just a table and a few columns, really) but it also emits the Javascript that does the animation. So the control is self-contained and pretty easy-to-use (IMHO).

Here's a demo, and here's the source. If you're using AJAX, try combining this with UpdatePanel, UpdateProgress and friends... pretty easy to achieve a decent user experience. Cheers.

Tuesday, January 23, 2007 5:55:16 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
ASP.NET | Javascript
 Thursday, January 18, 2007

Following are my notes from a WCF asynchrony demo I worked up a while back... thought it might interest somebody.

This WCF example works with the AdventureWorks demo database in SQL 2005. It illustrates mixing and matching synchronous and asynchronous processing in a WCF service and client. Specifically, the code shows:

- synchronous client code invoking synchronous service code ( not a big deal, admittedly :-) )
- synchronous client code invoking asynchronous service code
- asynchronous client code invoking synchronous service code
- asynchronous client code invoking asynchronous service code

 

Support for asynchrony is baked directly into the WCF contract (interface definition) using the AsyncPattern property of OperationContractAttribute. Such an interface also must adhere to the .NET asynchronous execution pattern (BeginXXX and EndXXX method pairs, use of IAsyncResult call object, support for callbacks, etc.). Here's the contract definition from the demo (edited down a bit for easy reading):

 

[ServiceContract]
public interface IAdventureWorksDataServiceAsync
{
	[OperationContract(AsyncPattern=true)]
	IAsyncResult BeginGetSalesPersonData(AsyncCallback cb, object state);

	SalesDataTable EndGetSalesPersonData(IAsyncResult result);
}

[ServiceContract]
public interface IAdventureWorksDataServiceSync
{
	[OperationContract]
	SalesDataTable GetSalesPersonData();
}
 

The important point here is that sync/async processing is a local implementation detail of clients and/or services. With WCF, the choice of synchronous/asynchronous processing on one end of the wire need not surface in the programming model on the other end. The demo client code can make calls against IAdventureWorksDataServiceSync, and the server can process such requests on an object that implements IAdventureWorksDataServiceAsync, or vice versa.

 

Think about that for a moment... it's pretty cool that the WCF infrastructure gives this to us for the cost of a few attributes. It's not unlike async page processing in ASP.NET, where the client just types in a URL and has no idea that special ThreadPool magic is happening on the server. 

 

A few additional points:

 

- Notice that, in the cases where you have sync <==> async processing (or vice versa), the client and server endpoint contracts don't reference the exact same physical interface definition; "matching" client and server contracts must be type-compatible, but not necessarily modeled on the exact same interface.

- The server-side benefits to async processing are primarily 2 fold: 1) separate the resources (threads, in this case) needed for accepting requests from the resources (threads) needed to process requests, and 2) spend as little time as possible accepting requests (as opposed to processing them, which "takes as long as it takes").

- The oft-repeated client-side benefit to async processing is the ability to not tie up a UI thread waiting for a remote request to return a response. The demo illustrates this.

- For a bit of insight into what happens inside ThreadPool, pay attention to the console output of Host.exe, and take a look at the async Start and End methods on the server side.

 

Enjoy!

Thursday, January 18, 2007 8:27:16 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
WCF
 Wednesday, January 17, 2007

Note to self... when using <location> tags in your web.config file, like so:

 

<location path="SomeFile.aspx">
	<system.web>
		<authorization>
			<allow users="*"/>
		</authorization>
	</system.web>
</location>

DO NOT use root-relative paths (AKA "tilde" paths) to specify the path attribute value... otherwise you spend several hours trying to figure out why your location-specific configuration overrides aren't being honored at runtime.

Or so I've heard. <sigh>

Wednesday, January 17, 2007 9:30:16 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
ASP.NET
 Sunday, January 14, 2007

Yesterday, Cary and I hiked the summit of Blood Mountain with Mallory, Darby, and Reggie. This is the highest point of the Appalachian Trail in Georgia, at 4458 feet. The weather was overcast, so the views weren't quite as good as on a bluebird day, but still worth the effort. We followed the east-to-west route from Neel's Gap up to the summit... it's about a 2.5 mile hike each way, with roughly a 1500 foot elevation gain. Fairly strenuous, and all the more so with a little girl strapped to your back!

Despite a few rough patches with the girls (they were getting pretty hungry as we neared the summit :-) ), it was a great trip. Here's a few pictures we took at the summit.

 

The whole gang, including Reggie

the whole gang on blood mountain  

Cary and the girls near the summit shelter, built in the 1930s by the CCC

blood mountain shelter

Mallory, Daddy, and Darby

blood mountain shelter2

Daddy "getting some exercise"

j and m on blood mountain

Darby expressing her dissatisfaction with riding vs. walking

c and d on blood mountain

Sunday, January 14, 2007 10:47:16 AM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
Hiking
 Thursday, January 11, 2007

I've been digging into the ASP.NET AJAX bits over the last few days... impressive stuff. As a developer who will have his static typing pried from his cold dead fingers, I *especially* appreciate the high "enabled functionality per lines of hand-written Javascript" ratio.  :-)

As an aside, I know it's very trendy to fawn all over Ruby and Javascript and the like, and I appreciate the movement toward dynamic language-like features in C# 2.0/3.0. But there's still TONS of useful work being done in crusty ol' statically typed languages. Let's not burn our "Learn C++ in 7 Minutes" books just yet.

Well, okay... maybe *those* books. But you see my point.

Anyway... back to AJAX. There are several ways to utilize the framework; the easiest is to drop an UpdatePanel and ScriptManager on your ASP.NET page, then add some child controls to the UpdatePanel. You then have the ability to update these child controls without refreshing the entire page. Note that you still end up doing a server POST (via written-for-you Javascript) to refresh the state of those controls, but that same Javascript gets the results of the postback and modifies the browser DOM to update the child controls of the UpdatePanel with their new state. The effect is that portions of your page are updated without doing a full browser refresh. Slick.

Where this really gets interesting is that you can combine UpdatePanel with some interesting client-side animations to indicate to the user that updates are occuring/have occured. Again, the amount of Javascript you have to write is, in many cases, none!

As a test, I wanted to use the MultiView control to display views (groups of controls) on a page. I wanted view switching to not require a page refresh (meaning, use UpdatePanel), and I also wanted some sort of neato (read: annoying and distracting) animation effect to occur each time the user switches views.

Here's what I came up with.  Interestingly, the "fade out" effect doesn't seem to work very well from the server (worked fine locally on the ASP.NET dev webserver). Source is here (you'll need this and this along with .NET 2.0 to run it): 

I imagine this is all very pedestrian to the AJAX long-timers, but I thought it was cool.

Thursday, January 11, 2007 4:36:16 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
AJAX | ASP.NET
 Sunday, January 07, 2007

Hey, now this is cool... DM instructor Mark Smith blogs about his quest to solve once and for all the mystery of how concurrent GC works in .NET.

 

I remember discussing this a few months back with Andy Clymer and Rich Blewett, DM instructors themselves.  We couldn't come to a conclusion in the little time we spent on it... glad to see the case has been cracked!

 

To summarize... concurrent GC (which trades off responsiveness in GUI apps for increased resource consumption and longer total time spent doing GC) can occur on single- and multi-threaded machines, and is the default in the workstation version of the GC (concurrent GC makes no sense in the context of a server app).

Sunday, January 07, 2007 9:26:16 PM (Eastern Standard Time, UTC-05:00)  #    Comments [0] -
GC
Disclaimer

Don't blame my employer(s)... all of this is my fault.

© Copyright 2008 Josh Lane
Sign In
Locations of visitors to this page
DasBlog theme 'Business' created by Christoph De Baene (delarou)