Skip to main content

Posts

Showing posts from 2008

Asynchronous pages in C# - When to Use It?

When do we need asynchronous page in ASP.net. Suppose you have a website with two web pages. One is your home page which display's a greeting, and the second page displays a large dataset from a database. You have 25 threads in your thread pool. 25 people simultaneously are accessing the database query page, and one additional person comes onto the site to see the home page which has static content on it. http://davidjberman.com/blogs/csharp/archive/2007/08/13/how-to-create-asynchronous-asp-net-pages-using-c.aspx

How to Send Many Parameters to the Thread

There are some ways to send number of parameters to the new created thread. 1. Creating a new instance of a class, and using that instance to store the information 2. Using ThreadPool to send parameters 3. Calling a delegate asynchronously More detailed information can be found at: http://www.yoda.arachsys.com/csharp/threadstart.html

Reverse Linked List Function - Interview Question

Here is code that should reverse Linked list: Linked list class: class Node { int ID; string name; Node next; } First option (recursive function): Node Reverse(Node root) { PutOnTop(root, root.Next) } Node PutOnTop(Node newRoot, Node current) { Node next = current.Next; current.Next = newRoot; if(next.Next!=null) PutOnTop(current,next); } Second option (without using recursive function): Node Reverse(Node root) { Node current = root.next; Node prev = root; while(current!=null) { Node next = current.Next; current.Next = prev; prev = current; current = next; } }

Dynamic Data Error - "'DropDownList1' has a SelectedValue which is invalid because …"

During my first investigation of Dynamic Data Support at .NET 3.5 environment, I've found that even Microsoft has bug :-))) After the following great instructions of following screen-cast I've finished in few minutes with applications that allows me to maintain all my database tables. The problem is that already at third screen I've played with I got following error message: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items. Fortunately, I'm not the first who is plying with Dynamic Data at .NET 3.5 so at this blog you can find fix and good explanation of this bug.

Catch Unhandled Exceptions in Winforms Application

ASP.NET web application allows us to you implement IHttpModule interface to catch all unhandled exception. Similar way we can catch all unhandled exceptions in winforms applications by handling AppDomain.CurrentDomain.UnhandledException event. The main idea is to do something like this: static void Main( string [] args) { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); } In the implementation of the CurrentDomain_UnhandledException method, we can write to the log, close some open handles and most important - show a pleasant message to the user. static void CurrentDomain_UnhandledException( object sender, UnhandledExceptionEventArgs e) { try { // Write to the log, close handels, … // Show message box. } finally { Application.Exit(); } } code source