开发者

Making an async call from an ASP.Net page-- recommended ways?

We'd like to track who's on our website and what pages they're looking at. The plan is to create a delegate (which will log visits to开发者_StackOverflow a database table) and call it asynchronously.

We're using .Net 3.5 and I don't know if the delegate idea, along with BeginInvoke and EndInvoke, is the way to go these days or if there are newer, improved methods-- a BackgroundWorker possibly, or something else. Not sure.

The idea is to keep as light an overhead as possible, since this processing will take place each time one of our pages is called. If we use a delegate it won't return a value, that's for sure. If you have any suggestions I'm glad to hear them. Thanks!


Well if you are looking to just run a process and not wait for it to finish another easy way to do it would be to just kick off a new thread and run your code on that. Then you don't have to wait for it to return. Similar to the thought about the backgroundworker.


ThreadPool.QueueWorkerItem is one simple way to do it. Just you logging request to the threadpool and it will do the action in a background thread, and you don't need to worry about it.


You could use Javascript with XMLHttpRequest to load your other page if that's the way you want to go.

Instead of creating a single page, I'd put it in a base page from which your pages inherit. Then, use any async method that you prefer.


Use the backgroundworker, won't use the ui thread, so won't slow your system down.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜